In this chapter, we are going to review a few concepts and additions to the domain notation in UML.
Composition and Aggregation
When objects of one class consist entirely of objects of another class it called a composition relationship.
Composition is a subset of a one-to-many relationship.
a team is composed of many members
an airplane is composed of seats
a parking lot is composed of parking places
When objects of one class are the components of objects of another class but the components of one class do not have to be part of the objects of the other class this is an aggregation relationship.
Implicitly, a composition relationship is a 1..1 relationship on the side of the owner (many to 1). This is to say that in the case of a
ParkingPlace relationship there are are no stray members of the
A variation of composition is aggregation. Aggregation relationship allows for strays. If we create a relationship between members of the
ParkingLot class and members of the
Car class,and we allow for cars to be parked on the street and not in the lot then we have an aggregation relationship.
Aggregation association is implicitly 0..1 - not all the many need to be associated with the 1.
In UML, a super class called
generalization and a subclass is called
specialization. We can change part of the domain diagram for the condominium domain to have a super class called
Inhabitant and with a subclasses of Renter and
AptOwner. When there is a subclass and a super class there is a hollow arrowhead pointing to the super class.
Now because an
Inhabitant cannot be both a renter and an owner, these subclasses are called
Furthermore every inhabitant of this of this building is in at least one of the subclasses, this is referred to as a complete relationship.
However if we change the diagram to be this:
Now, because every Inhabitant doesn't need to be a
DogOwner or a
CatOwner then this is an incomplete relationship. Furthermore, because an
Inhabitant can own both a cat and a dog they can be in both classes. So this is described as an overlapping relationship. The relationship of subclasses and super classes can have any combination of complete/incomplete and overlapping/disjoint.
In UML we put this information in curly braces like this:
In order to clarify that the superclass and subclass are in this relationship we put an arrow between the classes to show the hierarchy.
Associations don't just have to be between classes. There can be associations within a class, these are called self-associations. If we want to keep track of which owners live with each other then we could construct an association with the
AptOwner class. We can also name this association.
We can also name the different roles in a self-association relationship.
This diagram shows that within the
Employee table are both managers and workers. Each worker must be associated with 1 manager and each manager can have between 1-5 workers whom he is responsible for.
The arrows show the directionality of the association. This is important when you are not showing the cardinality between the classes. Typically in this type of diagram, you'll show something that looks like a crows foot on the association line to reveal with is the many side of a relationship.
With aggregation, composition, subclasses and self-associations we get to dig deeper into how classes are related.
Next I'll show you some tools to draw the UML diagrams with!