C + + is-a was-a has-a holds-a
Flyfish 2015-1-28
Is-a: Public inheritance generally referred to as two objects is a is-a relationship
Was-a: Private inheritance called two objects is a was-a relationship
Has-a:has-a relationship describes an instance of another type in a class
HOLDS-A: Describes a class that holds a pointer to another type or reference
Is-a: The Liskov substitution principle (Liskov Substitution Principle) makes a more restrictive definition of is-a
A subclass object can be used to replace its base class object. Every thing that applies to base classes must also apply to derived classes,
Because each derived class object is also a base class object.
Where Is-a and was-a are inheritance relationships. Has-a and holds-a are combinatorial relationships.
Reasons to use combinatorial relationships as much as possible
Inheritance makes the design more tightly coupled, and when one class inherits from another, the subclass can gain access to all public and protected members of the base class, regardless of the permission inheritance.
This class is only coupled with the public members of other classes when using composition.
When you use a holds-a relationship, you do not need to refer to the header files of other classes, only the predecessor declaration is used.
C + + is-a was-a has-a holds-a