Useimplementation inheritance to override behavior

Use private and protected base classes or private and protected derivation to inherit behavior or override it when you don't need to inherit public protocol. Implementation inheritance is often appropriate for inheriting from a framework to override behavior. For example, MRemoteCaller and MRemoteDispatcher in the Taligent Client/Server framework are usually inherited as protected base classes.

When a derived class inherits from a private or protected base class, the derived class has access to all the members of the base, but they are not publicly exported as members of the derived class. For clients, it also means that the derived class is not treated as a subtype of the base class, and no automatic conversions are performed for function arguments or assignments. However, this is only true outside the derived class; within the derived class, the behavior is exactly as if the base class had been declared public.

NOTE C++ lets you reexport public members of private or protected bases via access control declarations.

As with type inheritance, if you want to share only portions of a base class' protocol, make the class private and reexport the members you want to make public. If a class is used by another class purely in a client relationship, that class should be a member rather than a private or protected base class. Use private or protected base classes only when behavior is inherited or overridden, as in a framework.

[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