An example of delegating to a member

The following is an example of a class template that delegates the implementation to a member. It has two main features:

The type-specific protocol is encapsulated in a small standalone abstract base class; public class template creates concrete instances.

The public class template has an implementation class as a member, which has a pointer to the type-specific protocol class.

While there are more classes involved, and more delegation, this design is cleaner than the private implementation example on page 155. Because the type-specific class is passed into the implementation class, the implementation class constructors and destructors are free to use the type-specific operators. So there is no need to treat construction or destruction specially.


[Contents] [Previous] [Next]
Click the icon to mail questions or corrections about this material to Taligent personnel.
Copyright©1995 Taligent,Inc. All rights reserved.

Generated with WebMaker