Designing a base class this way creates a template of behavior by providing an implementation
to inherit. Your derived classes can then inherit from this base template and implement
the details.
Nested Classes
You define nested classes within the scope of another class definition. Classes that are defined
within the scope of a namespace, but not inside the scope of another class, are called non-nested
classes. Nested classes have some special capabilities and lend themselves well to situations
where you need a helper class that works on behalf of the containing class.
For example, a container class might maintain a collection of objects. Imagine that you
need some facility to iterate over those contained objects and also allow external users who
are doing the iteration to maintain a marker, or iterator of sorts, representing their place during
the iteration. Using nested classes this way is a common design technique that prevents
users from holding onto direct references to the contained objects, and it gives you greater
flexibility to change the internal behavior of the container class without breaking the code
that uses the container class.
Nested classes have access to all of the members that are visible to the containing class,
even if they??™re private.
Pages:
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100