Composition

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.

A Composition

Understanding Composition

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.

Creating a Composition Relationship

To create a Composition relationship in Modeldraw:

  1. Select the Composition tool from the toolbox

  2. Click on the part (contained) Class

  3. 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.

Last updated