Uml Class Diagram Association Vs Dependency

next → ← prev

UML Association vs. Aggregation vs. Composition

In UML diagrams, relationships are used to link several things. It is a connection between structural, behavioral, or grouping things. Following are the standard UML relationships enlisted below:

  • Association
  • Dependency
  • Generalization
  • Realization

Association

Association relationship is a structural relationship in which different objects are linked within the system. It exhibits a binary relationship between the objects representing an activity. It depicts the relationship between objects, such as a teacher, can be associated with multiple teachers.

It is represented by a line between the classes followed by an arrow that navigates the direction, and when the arrow is on both sides, it is then called a bidirectional association. We can specify the multiplicity of an association by adding the adornments on the line that will denote the association.

Example:

1) A single teacher has multiple students.

UML Association vs. Aggregation vs. Composition

2) A single student can associate with many teachers.

UML Association vs. Aggregation vs. Composition

The composition and aggregation are two subsets of association. In both of the cases, the object of one class is owned by the object of another class; the only difference is that in composition, the child does not exist independently of its parent, whereas in aggregation, the child is not dependent on its parent i.e., standalone. An aggregation is a special form of association, and composition is the special form of aggregation.

UML Association vs. Aggregation vs. Composition

Aggregation

Aggregation is a subset of association, is a collection of different things. It represents has a relationship. It is more specific than an association. It describes a part-whole or part-of relationship. It is a binary association, i.e., it only involves two classes. It is a kind of relationship in which the child is independent of its parent.

For example:

Here we are considering a car and a wheel example. A car cannot move without a wheel. But the wheel can be independently used with the bike, scooter, cycle, or any other vehicle. The wheel object can exist without the car object, which proves to be an aggregation relationship.

UML Association vs. Aggregation vs. Composition

Composition

The composition is a part of aggregation, and it portrays the whole-part relationship. It depicts dependency between a composite (parent) and its parts (children), which means that if the composite is discarded, so will its parts get deleted. It exists between similar objects.

As you can see from the example given below, the composition association relationship connects the Person class with Brain class, Heart class, and Legs class. If the person is destroyed, the brain, heart, and legs will also get discarded.

UML Association vs. Aggregation vs. Composition

Association vs. Aggregation vs. Composition

Association Aggregation Composition
Association relationship is represented using an arrow. Aggregation relationship is represented by a straight line with an empty diamond at one end. The composition relationship is represented by a straight line with a black diamond at one end.
In UML, it can exist between two or more classes. It is a part of the association relationship. It is a part of the aggregation relationship.
It incorporates one-to-one, one-to-many, many-to-one, and many-to-many association between the classes. It exhibits a kind of weak relationship. It exhibits a strong type of relationship.
It can associate one more objects together. In an aggregation relationship, the associated objects exist independently within the scope of the system. In a composition relationship, the associated objects cannot exist independently within the scope of the system.
In this, objects are linked together. In this, the linked objects are independent of each other. Here the linked objects are dependent on each other.
It may or may not affect the other associated element if one element is deleted. Deleting one element in the aggregation relationship does not affect other associated elements. It affects the other element if one of its associated element is deleted.
Example: A tutor can associate with multiple students, or one student can associate with multiple teachers. Example: A car needs a wheel for its proper functioning, but it may not require the same wheel. It may function with another wheel as well. Example: If a file is placed in a folder and that is folder is deleted. The file residing inside that folder will also get deleted at the time of folder deletion.

Next Topic UML Association

← prev next →

Source: https://www.javatpoint.com/uml-association-vs-aggregation-vs-composition

Posted by: freeshugonoes.blogspot.com

Posting Komentar

Lebih baru Lebih lama