UML diagrams are a handy way of understanding and linking between the structural or grouping entities. Good knowledge of all the technicalities and a thorough understanding of the logical relationship concepts are important for executing object-oriented programming.
UML helps in figuring out how one or more things are associated with each other. The most common type of relationship is Association. Let’s have a look at it in detail.
What is an Association Relationship?
In layman’s language, association relationships are defined as the relationship between two separate units. The commonality is searched between entities and links are made between them. The association allows making logical connections through a continuous reference.
Associations are represented in a UML diagram by a single solid line connecting the same or different classes. The association can be shown between one-to-one, one-to-many, many-to-many classes. Since association relationships mark a communication link between two entities, they should not be ambiguous and labeled clearly. The labeling is followed by a small arrowhead for a better understanding of the relationship.
As seen in the example picture below the association relationship is represented between a bank and its employ. Multiple solid lines originate from the main class, i.e: bank, this diagram shows a one-to-many association relationship.
Generalization VS Association
As the name suggests, generalization is a way of classifying similar objects in a more generalized manner. The entities show a parent-child relationship between a general entity and a unique one with the latter being a specialized form of the general class. In comparison, the association links different entities and represents how one class uses the functionality of the other linked object.
The generalization represents the ‘kind-of’ relationships, while the association helps show the ‘has-a’ relationship. This means that generalization is linked with displaying the inheritances while the association shows the linking based on commonalities.
All-in-One Diagram Software
- Superior file compatibility: Import and export drawings to various file formats, such as Visio
- Cross-platform supported (Windows, Mac, Linux, Web)
Types of Association Relationships
Depending on the linking, the association is further divided into four main types. It is classified as below:
Multiplicity association refers to cases when a linked class appears multiple times. Instead of restating the entity, we specify the maximum and minimum instances that it can be linked. Therefore, in such relationships, we mark an asterisk with the association line. The asterisk represents an intermediated maximum.
The image below assists in understanding how multiplicity can be expressed in different circumstances.
2. Directed Association
As the name indicated, directed association refers to the direction of communication flow within an association relationship. By default, the association relationships are navigable bilaterally; however, the directed association helps in directing the flow in one direction only. The directed association is represented by a presence of a solid line with an arrowhead.
Here, a unidirectional association is shown between a server and the client. The arrow’s direction shows that a server can process the requests of a client.
3. Reflexive Association
The reflexive association is described as the relationship between the instances of the same class. Such an association is further classified into two types: Symmetrical and Asymmetrical Association Reflex. There is no specific symbol allotted to it; however, the relation points back to the same class.
Aggregation VS Composition
Aggregation and Composition are two subsets of association; however, the composition is a further subset of the aggregation relationship. In simple words, aggregation can be defined as when the objects of one class can access the entities of another class. Whereas the composition represents a bilateral relationship and the object is part of only one composite at a time.
Aggregations Represented in a UML Diagram
Aggregation is an association in which the entities are configured together to create a more complex object. A group of objects and their common linking is described through it. It defines a single point of control, called the aggregate and the group of objects representing the assembly.
In a UML diagram, the data flows from the aggregate (parent class) towards the assembly (child class) with a diamond shape (unfilled) near the former class. The part classifier, or the assembly entities, can be linked to more than one aggregate and exist independently.
This example shows that the car always needs a wheel and an engine to work correctly, whereas the engine and wheel do not always need a car. They can be used with a bus, a bike, machines, lawnmower, and much more. Similarly, the engine is necessary for an engine inspection, but the engine can exist as an independent entity and be associated with other vehicles as well.
Compositions Represented in a UML Diagram
Compositions are also a type of association representing a two-way, highly dependant relationship between two different classes. If the composite is deleted, the other entities linked with it are also deleted.
It depicts dependency between the parent and child. In a UML diagram, draw a line between the parent and child class with a filled diamond shape near the parent class.
As illustrated in this example, a person has legs, a heart, and a brain. If the focal point of this diagram, the person is hurt and killed, all the composite entities will also be discarded. Unlike aggregation, the entities can not exist independently and are a ‘part of’ the person.
|A subset of association||A subset of aggregation.|
|A weak type of association.||A strong type of association|
|Linked objects are independent of each other.||Linked objects are highly dependant on each other.|
|Represented with a solid line and an empty arrowhead.||Represented by a solid line with a filled arrowhead.|
|Aggregation is defined as a ‘has-a’ relationship.||Composition is defined as a ‘part-of’ relationship.|
Is Composition Better than Aggregation?
Composition is stronger than aggregation. A relationship between two objects is cited as an association, and both of these terms are a sub-type of it.
If two objects exist independently of each other and do not imply any ownership of each other, they are referred to as the aggregation association. However, if two objects in a system need to coexist and depend on each other, they are labeled as composition. Such an association is termed ‘strong’ since when the owning object is destroyed, so are the linked objects. On the contrary, aggregation represents a weak association because the life of the contained object does not depend on the container object.
Use EdrawMax for UML Diagram Creation
Association is the most basic yet the most important type of linking relationship that allows you to connect objects of a system. It is essential that we differentiate between its two types, aggregation, and composition, for an error-free implementation and the creation of their UML diagrams.
Creating the UML diagrams for association is super-easy if you have a user-friendly and tool abundant software like EdrawMax. With an extensive range of editing tools, a highly customizable library, and multiple template options creating a good UML in just a few clicks is just a five-finger thing. Whether you are a newbie or tech-savvy, understanding and handling the software is super-easy. Download it to start creating the most meaningful and innovative diagrams in just a go!