Virtual Classes Logo          Virtual Classes
    Read Anytime,Anywhere

Composition

Composition is a specialized form of Aggregation. It is a strong type of Aggregation.
In this relationship, child objects does not have their lifecycle without Parent object. If a parent object is deleted, all its child objects will also be deleted. This represents 'death' relationship.
Composition is represented by a solid diamond followed by a line.

Let’s take an example of relationship between CAR and ENGINE. A CAR has a ENGINE. There is no independent life of ENGINE and an ENGINE cannot belongs to two different CARS, if we delete the CAR then the ENGINE will also be deleted automatically .
composition example



Let’s take another example of relationship between Questions and options. Single questions can have multiple options but option cannot belong to multiple questions. If we delete questions then options will also be automatically deleted.