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:
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
Discussion & Comments