UML – Association

Association
-> Association between classes most often represent instance variables that hold references to other objects.

Aggregation
-> Inner object’s lifetime is not controlled by outer object’s lifetime.
-> Classroom and students. If a class room is destroyed students are not destroyed.
-> This is represented in diagrams by diamond.
-> Aggregation gives us a ‘has-a’ relationship. Within aggregation, the lifetime of the part is not managed by the whole.

Person would then be used as follows:

or

As you can see, Person does not manage the lifetime of Address. If Person is destroyed, the Address still exists. This scenario does map quite nicely to the real world.

Containment (Composition)
-> Inner object’s lifetime is controlled by outer object’s lifetime.
-> Window and button. If window is closed button is also destroyed.
-> Composition gives us a ‘part of’ relationship.
-> In UML diagram, its shows as filled diamond.

Leave a Reply

Your email address will not be published. Required fields are marked *