Composition Aggregation UML Class Diagram For Composition and Aggregation
Composition Aggregation UML Class Diagram For Composition and Aggregation
Composition
Aggregation
UML Class Diagram for Composition
and Aggregation
Composition
Composition
Composition
Aggregation
Multiplicity
For each of the three class relationships, DealershipCar, Dealership-SalesPerson, and Dealership-Manager,
is the relationship composition or aggregation?
Define one class for the whole and define separate classes for
each of the parts.
For a class that contains another class, declare an instance
variable inside the containing class such that the instance variable
holds a reference to one or more of the contained class's objects.
Typically, for association lines with * multiplicity values, use an
ArrayList to implement the instance variable associated with the
asterisked class.
If two classes have an aggregation relationship with non-exclusive
ownership, then store the contained class's object in an instance
variable in the containing class, but also store it in another
variable outside of the containing class, so the object can be
added to another aggregation and have two different "owners."
If two classes have a composition relationship, then store the
contained class's object in an instance variable in the containing
class, but do not store it elsewhere. That way, the object can have
only one "owner."
10
11
12
13
14
34
35
Assume it's a game like war or gin rummy where you have a
deck of cards and two players.
Decide on appropriate classes. For each class, draw a UMLnotation three-partition rectangle and put the class name in
the top partition.
Look for composition relationships between classes. For each
pair of classes related by composition, draw a composition
connecting line with a diamond next to the containing class.
For example, the left composition association line below is for
Game, the containing class, and Deck, the contained class.
36
37
39
composition
implementati
on
{
public static final int
GroupOfCards groupOfCards =
new GroupOfCards();
TOTAL_CARDS = 52;
public Deck()
public Deck()
{
for (int i=0; i<TOTAL_CARDS; i++)
{
groupOfCards.addCard(
addCard(
} // end constructor
} // end constructor
...
...
40
41