Composition
Last updated
Last updated
Composition is a strong form of association in UML that represents a whole-part relationship between Classes. In a composition, the lifetime of the part (contained object) is dependent on the lifetime of the whole (container object). Modeldraw allows you to easily create and manage Composition relationships to accurately model these strong dependencies in your system design.
Composition represents a strong "has-a" or "contains" relationship between classes. Key characteristics include:
The part (contained object) cannot exist independently of the whole (container object)
If the whole is destroyed, its parts are also destroyed
A part can belong to only one whole at a time
The whole is responsible for the creation and destruction of its parts
Composition is represented in UML by a solid line with a filled diamond at the end of the whole (container) class.
Examples of composition:
A House (whole) and its Rooms (parts)
A Car (whole) and its Engine (part)
A University (whole) and its Departments (parts)
Composition differs from Aggregation, which is a weaker form of association where the part can exist independently of the whole.
To create a Composition relationship in Modeldraw:
Select the Composition tool from the toolbox
Click on the part (contained) Class
Move above and click the whole (container) Class
The filled diamond will automatically appear at the end of the whole class, indicating the strong ownership in the relationship.