• 20 hours
  • Medium

Free online content available in this course.

course.header.alt.is_video

course.header.alt.is_certifying

Got it!

Last updated on 11/25/19

Broach advanced UML subjects

Log in or subscribe for free to enjoy all this course has to offer!

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  ParkingLot to ParkingPlace  relationship there are are no stray members of the  ParkingPlace class.

An Aggregation Association
A composition association

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.

The Aggregation Association between the parkingLot class and the Car class
The empty diamond of the Aggregation Association between the parkingLot class and the Car class

Aggregation association is implicitly 0..1 - not all the many need to be associated with the 1.

Subclasses

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.

Note the hollow arrow pointing to the Generalization
Note the hollow arrow pointing to the generalization

Now because an  Inhabitant cannot be both a renter and an owner, these subclasses are called  Disjoint.

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:

Incomplete and Overlapping
Incomplete and overlapping

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:

Incomplete and Overlapping and saying so!
Incomplete and Overlapping and saying so!

In order to clarify that the superclass and subclass are in this relationship we put an arrow between the classes to show the hierarchy.

Self-associations

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.

A many to many self association
A many-to-many self-association

We can also name the different roles in a self-association relationship.

A One to Many self association relationship with each role specified
A One to Many self association relationship with each role specified

 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!‌

Example of certificate of achievement
Example of certificate of achievement