Distinguish is-a from has-a relationships

Failure to correctly distinguish between is-a and has-a relationships is a common design problem. It happens most often when a class should be a member, or a private base class is inherited as a public base class.

Use public base classes only when polymorphism is important, and the derived class is used through a pointer or reference to the base class.

Use a private or protected base when behavior is going to be inherited: polymorphism is not needed, but you want to use the class as a base internally, or the base will be called from within a framework. This is like public inheritance, but only visible to your own class or to a framework.

Use a member when behavior is only going to be used, and when your class is a client of
that behavior.


[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