A Short Story

 < Day Day Up > 



Early one morning some auto mechanics were gathered around a late model car that had manifested a few performance issues. They were talking among themselves offering different opinions as to what the problem could be when suddenly the shop supervisor walked up and yelled, 'OK everybody, back to work!'

On the back to work command one mechanic went back to tuning an engine, another mechanic started cleaning the garage bays, another started to rotate some tires, while yet another mechanic started to replace an exhaust system.

These shop mechanics exhibited polymorphic behavior; one back to work command caused each to start performing a different type of work.

Taming the Complexity of the C++ Language

To implement inheritance and dynamic polymorphic behavior requires the concurrent use of many complex C++ language features. You will master the language soon enough, but until you do it will be more helpful to think in terms of the inheritance behavior you desire from your design. Table 16-2 lists and describes the different types of inheritance behavior achieved with different C++ language features.

Table 16-2: Language Features vs. Inheritance Behavior

Feature

Behavior

base class

A base class provides generalized behavior. Subclasses that share a common base class will exhibit the common behavior supplied by the base class.

pure virtual function

A pure virtual function is an interface function that must be inherited and implemented. A subclass that inherits a pure virtual function but fails to provide an overriding implementation will become an abstract base class.

ordinary virtual function

A class inheriting an ordinary virtual function may accept the virtual function's implementation or provide an overriding behavior.

non-virtual function

A base class that declares and implements a non-virtual function prevents derived classes from overriding that function.

public inheritance

Public inheritance means the derived class is implementing 'is a...' behavior.

private inheritance

Private inheritance will block client access via the derived class to any public member functions in the base class. When private inheritance is used there is no conceptual relationship between the base and derived class since the base class's public functions are now private in the derived class.



 < Day Day Up > 



C++ for Artists. The Art, Philosophy, and Science of Object-Oriented Programming
C++ For Artists: The Art, Philosophy, And Science Of Object-Oriented Programming
ISBN: 1932504028
EAN: 2147483647
Year: 2003
Pages: 340
Authors: Rick Miller

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net