UML composition semantics: In composition, is a part object owned exclusively by a single composite and thus not shared across multiple aggregates?

Difficulty: Easy

Correct Answer: Correct

Explanation:


Introduction / Context:
UML models two strong forms of whole-part relationships: aggregation and composition. Aggregation is a shared association, while composition denotes strong ownership and coincident lifecycles. Understanding composition clarifies when parts may be reused or shared across multiple aggregates.



Given Data / Assumptions:

  • Composition is shown as a filled diamond at the composite end.
  • Parts have the same lifetime as the composite; when the composite is destroyed, its parts are destroyed.
  • A part instance belongs to at most one composite at a time.



Concept / Approach:
Because composition models exclusive ownership, a part cannot be shared among multiple composites simultaneously. For example, an Engine composed into a specific Car is not simultaneously part of another Car. If you need sharing, use aggregation or simple association. Composition maps naturally to design choices where resource ownership and cleanup are unambiguous.



Step-by-Step Solution:
Identify whole-part relationships; decide whether they require exclusive ownership and lifecycle binding.Model exclusive ownership with composition and non-exclusive with aggregation.Ensure code enforces single ownership (e.g., single parent reference).Design destruction semantics so parts are cleaned up with the composite.Avoid references that would allow the same part to attach to multiple composites concurrently.



Verification / Alternative check:
Translate the model into code: a part object should have a single parent pointer or factory ensuring exclusive creation and disposal. Attempting to attach the part to two parents should either be impossible or raise an error.



Why Other Options Are Wrong:
Incorrect: contradicts the UML definition of composition.Only for immutable objects or only in databases: composition is a general OO modeling construct independent of object mutability or persistence layer.



Common Pitfalls:
Confusing aggregation with composition, leaking references that outlive the composite, or modeling shared resources as composed parts.



Final Answer:
Correct

More Questions from Object-Oriented Data Modeling

Discussion & Comments

No comments yet. Be the first to comment!
Join Discussion