0

In Object Oriented when I create a class variable and initialize it in my constructor could we say that it's an UML aggregation? In the same idea could we say that a variable defined in a method is an UML association?

What are the links between UML association / aggregation / composition and OO class?

Bastien Vandamme
  • 17,659
  • 30
  • 118
  • 200

3 Answers3

1

In general, compositions are special cases of aggregations which are special cases of associations. What you use depends on the model, i.e. on the properties of the association.

UML doesn't deal with the actual implementation and you could as well implement a model described by UML in a non-OO way.

As for your question for the link between UML associations and class/instance members: basically every member that references another class is an association (even though primitive wrappers like String or Integer in Java normally don't count).

Thomas
  • 87,414
  • 12
  • 119
  • 157
  • +1 for the simple association. Aggregations have been dropped in UML 2.0, so you don't usually have to think about them. – Mister Smith Jan 27 '12 at 13:53
1

Association means that there is a relation. Aggregation/composition further refine some additional details.

Aggregation means that there is a relation but there are no known constraints on the parent which regard the lifetime management of dependent entities.

Composition means that there is a relation and the parent object is responsible for the lifetime management of the dependent entity/entities.

Wiktor Zychla
  • 47,367
  • 6
  • 74
  • 106
-1

Just to summarize my comments on this page:

  • In Java, most of times an instance variable is represented as a regular association in UML.
  • In UML 2.0 aggregations have been dropped so you don't have to worry about them.Seems that aggregations were dropped but added back again.
  • Compositions are infrequent in Java since you have to guarantee that the child object is not used after his parent "dies". This usually mandates passing defensive copies on parent's getters and deep cloning. In other languages they are more frequently used.
Mister Smith
  • 27,417
  • 21
  • 110
  • 193
  • Documentation I read about UML 2.0 define aggregation. Where do you read in UML 2.0 aggregations have been dropped? – Bastien Vandamme Jan 27 '12 at 14:42
  • Of course, aggregations and compositions were not dropped in UML 2 - See Role (Properties) in Association Package in the Infrastructure document. – Christian Jan 27 '12 at 15:51
  • Read here: http://books.google.com/books?id=ESQGjpQiLX4C&pg=PA50&lpg=PA50&dq=aggregations+dropped+UML+2.0&source=bl&ots=X6__MQmpri&sig=NBy5ruMPfqM46r4YQFXwyvO0-Tk&hl=en&redir_esc=y – Mister Smith Jan 30 '12 at 15:18
  • Despite there are many references in the web, I also think that aggregations are still in UML 2.0... Maybe someone can shed light on this? – Mister Smith Jan 30 '12 at 15:24
  • To light this go back to your second link. There is a comment : "At the bottom of that link, there's this entry though: "To clear the confusion, I e-mailed the author of The Object Primer, Scott Ambler, for clarification. He said that aggregation is back in UML 2.0 due to significant complaining within the community. Thanks." So, start drawing them again... – Dopyiii Apr 10 '09 at 17:18" – Bastien Vandamme Jun 12 '12 at 10:57