Class Relationships

When one class inherits from another, there is some inherent relationship between the classes. Defining what that relationship is, is just a matter of carefully considering how the classes are used. If a class inherits from another class and is simply a special case of that base class, then the derived class has an is-a relationship with the base class. Consider the case where you have a class called animal and another class called dog, which inherits from animal. You then have an is-a relationship. The class dog, is an animal.

When one class contains another, as in Examples 11.5 and 11.6, you have a has-a relationship. The practical example would be that if you had a class called car, that uses a class called engine, then the relationship would be a has-a relationship, the car has an engine.

C++ Programming Fundamentals
C++ Programming Fundamentals (Cyberrookies)
ISBN: 1584502371
EAN: 2147483647
Year: 2005
Pages: 197
Authors: Chuck Easttom © 2008-2017.
If you may any questions please contact us: