Link and association in UML represent the relation between objects and classes. Link is used to establish the relation between the objects in the object diagram. Association is used to represent the relation between the classes.
In the problem statement provided to develop the software, link and association are presented by the verb. In this section, we will be discussing the link and association in the context of object-oriented analysis and design.
Content: Link and Association
Definition of Link and Association
Link defines the relationship between two or more objects and a link is considered as an instance of an association. This means an association is a group of links that relates objects from the same classes. This can be easily understood with the help of an example.
Let us take the two classes Person and Company. Now there is an association relation between these two classes. Let’s say a person may own stock in zero or more companies. And it can be related in reverse that a company may have several persons owing its stock.
The object diagram below shows the links between the objects of person and company class.
The class diagram below shows the association between the person and the company class. Both link and association are represented with a line in UML notation.
Association Name
Association name is the name that reveals the kind of relation between the classes. While modelling, it not mandatory to name the association until it is unambiguous. Multiple associations between the same classes then it might create confusion.
This ambiguity in the model compels to name the association between classes. For example, a person own stock in a company and person works for a company. So, to resolve the ambiguity you must name the association.
Association Direction
Associations are bidirectional. When the association is established between two classes we can travel in both directions. The direction of traversing depends on the name of the association. Like, in the figure above, the association name between the two classes person and stock be Worksfor. So, we navigate as a person works for a company i.e. this association connects a person to a company.
If we name the association as Employs then we will navigate as a company employs a person i.e. this association connects a company to a Person. It is optional while modelling but if applied it prevents confusion.
Association End Names
Associated end names allotted to the ends of the association, ease in traversing the associations. Let us take the above example of two classes person and company and their participation in the association ‘Worksfor’. Now if we name the association ends i.e. the association end at the person side would be named ‘employee’ and the association end at the company side would be ‘employer’. It eases traversing the association.
Considering the binary association, every end of the association refers to an object or a set of objects associated with its respective source object.
As we have seen that there can be multiple associations between two classes. The association end names also help in identifying the type of association between the classes. Now we will discuss the properties of association end names
1. Multiplicity
Multiplicity is defined as the number of occurrences of one class that is associated with the single occurrence of its associated class. Accordingly, the multiplicity defines the number of associated objects of the same classes in the model. The figure below shows the many-to-many multiplicity.
The figure below shows the one-to-one multiplicity.
2. Ordering
In case we have objects with ‘many’ associated ends and there is no order then we can consider it as a set. But sometimes the occurrence of objects has an explicit order. For example, consider the example below.
On one screen there can be multiple windows overlapped. The occurrence of each window on the screen is at most once. The window at the top is visible to the user.
The ordering property is a part of the association. To mention that the set of objects are ordered you can add “{ordered}” at the association end of that set of objects.
3. Bags and Sequence
As we have seen earlier in a binary association, the association between two objects is represented by a single link. But when the object from the same classes has multiple associations then you can represent it with multiple links between the pair of objects of same associated classes. You can do this by writing the “{bag}” or “sequence” at the association end.
The bag is a collection of elements permitting the duplicates whereas sequence is the ordered collection of elements allowing the duplicates. For example, a route may involve a visit to multiple airports. So, this association end must be noted by {sequence}.
The only difference between sequence and ordered is that the sequence allows duplicates whereas ordered don’t.
4. Qualified Association
As we have discussed above there can be multiple associations between the classes, the qualified association helps in avoiding the confusion about the object with ‘many’, association end. The qualified association presents an attribute named qualifier that disambiguates the association ends of the object.
The qualifier can be defined for one-to-one and many-to-many association. A qualified association adds more information to the class model. For example, a bank has several accounts and each account has a unique identity due to the account number. So, here the account number act as the qualifier.
Association Class
A class object is defined with the attributes of the class. Similarly, the links of an association can be described with the attributes. This representation is called an association class. The way classes have attributes and operation, the association class also has attributes and operations.
The instances or the occurrences of the association class retrieve its identity from the instances of the constituent classes. You can identify the association classes by identifying adverbs in the problem statements.
Key Takeaways
- Link is the relation between the objects.
- Association is a group of links where each link is an instance of the association.
- If there are multiple associations between the same classes then to avoid the ambiguity associations can be named.
- Associations are bidirectional, the direction of navigation depends on the name of the association.
- An association has two ends that can also be named for the conveniently traversing the association.
- Association end names are less confusing than the association names.
- Multiplicity refers to the ends of association and describes the number of instances of one class associated with the instances of other class.
- The association ends can be ordered by writing the “{ordered}” at the end of association where the objects have an explicit order avoiding the duplicates.
- A pair of objects with multiple links can be represented by the association end with {bag} or {sequence}.
- Bag and sequence both are the collections of elements except that later one is ordered collection of elements permitting the duplicates.
- A qualified association removes the confusion for the object with many associate ends.
- The qualified association is an attribute that qualifies the association between two classes.
- Association class is a class where the links of the association are described as attributes.
- Association class adds more information to the class model.
So, this is all about the link and association which describes the relationship between the objects and classes in the class model. It helps in figuring out the adequacy
Leave a Reply