The composite object shares has-a relationships with the containing objects, and the underlying concept is referred to as object composition.
Composition vs. Inheritance
Class inheritance implies an is-a relationship, interface inheritance implies an is-like-a relationship, and composition implies a has-a relationship.
Always check whether the is-a relationship exists between the derived classes and the base class. If the is-a relationship does not hold, it’s better to use composition instead of inheritance.
No comments:
Post a Comment