Although inheritance is a very common practice in object-oriented programming, it is not the only way for classes to work together.

Composition, sometimes referred to as aggregation, is also appropriate in many circumstances.

Composition says that an object can be composed of other objects, rather than descend from other objects.

The best way to describe composition is by example, using a handy rule of thumb that asks “is a” or “has a.”

Post A Comment

Anti-Spam Quiz: