Wiki Home

UML Composition Vs Aggregation


Namespace: DotNet
People are sometimes confused when creating class diagrams, and specifying relationships, between composition and aggregation. To clarify, the definition of composition in UML states that deletes and copies are cascaded. Aggregation implies no such cascading. In Visual FoxPro, containership is composition whereas holding objects by reference is aggregation1.

In UML class diagrams both are shown with lines with diamonds at the aggregate end. In composition, the diamond is black-filled, and white-filled for aggregation.-- Steven Black

Footnotes:
(1) Composition code:
DEFINE CLASS MyForm AS FORM
ADD OBJECT MyTextbox AS TEXTBOX
MyTextbox is contained by MyForm. Contained objects are created in the constructor section or by later using the ADDOBJECT() method of the parent object.
Aggregation code:
DEFINE CLASS MyForm AS FORM
oCustom = NULL
FUNCTION INIT
THIS.oCustom = CREATEOBJECT( "MyCustom" )
MyCustom is not related in any way to MyForm, beyond the fact that MyForm is currently holding an object reference to MyCustom. You cannot refer to the Parent property of MyCustom to get at MyForm, for example.
See also: Aggregation Relationship and Composition Relationship
Category UML Category Class Design
( Topic last updated: 2000.01.10 09:58:03 PM )