Below are the types of relationships in UML:
1. Inheritance(is a) / Generalization: Indicates that source type inherits from the target type.
2. Interface Realization: Indicates that source type realizes the target interface.
3. Association: Represents a general relationship between instances of the classes.
e.g.
4. Directed Association: Directed association is related to direction of flow with in association classes.
In Directed association, the flow is directed. The association from one class to another class flows in single direction only.
e.g: A server can process requests of a client. This flow is unidirectional, that flows from server to client only. Hence a directed association relationship can be present within servers and clients of a system.
Server has access to Client but client doesn't have access to Server.
5. Aggregation: Indicates that the object at the end with diamond shape contains references to the object at the other end. If it contains that object exclusively, use a composition shape instead.
7. Composition(has a): Indicates that the source type has parts of the target type.
Association vs Aggregation vs Composition:
References:
1. Inheritance(is a) / Generalization: Indicates that source type inherits from the target type.
2. Interface Realization: Indicates that source type realizes the target interface.
3. Association: Represents a general relationship between instances of the classes.
e.g.
- An employee can be associated with multiple with multiple projects where as a project can have more than one employee.
- A Teacher is associated with multiple students.
4. Directed Association: Directed association is related to direction of flow with in association classes.
In Directed association, the flow is directed. The association from one class to another class flows in single direction only.
e.g: A server can process requests of a client. This flow is unidirectional, that flows from server to client only. Hence a directed association relationship can be present within servers and clients of a system.
Server has access to Client but client doesn't have access to Server.
5. Aggregation: Indicates that the object at the end with diamond shape contains references to the object at the other end. If it contains that object exclusively, use a composition shape instead.
- It is a type of Association.
- An object of one class can own or access object of another class.
- In Aggregation relationship dependent object remains in the scope even when the source object is destroyed.
- Aggregation is considered as a weak type of Association.
- e.g:
- A car needs a wheel to function correctly, but a wheel doesn't always need a car. It can also be used with the bike, bicycle or any other vehicle but not a particular car. Here the wheel object is meaningful even without a car object. Such type of relationship is called an Aggregate relationship.
- A car needs a wheel but doesn't always require the same wheel . A car can function adequately with another wheel as well.
7. Composition(has a): Indicates that the source type has parts of the target type.
- Composition is a sub type of Aggregation.
- It is a two association between the objects.
- It is a whole or part relationship.
- If a composite is deleted all other parts associated with it are deleted.
- Composition is considered as a strong type of Association.
- e.g: The folder contains many files, while each file has exactly one folder parent. If a folder is deleted all contained files in the folder are also deleted
Association vs Aggregation vs Composition:
- Aggregation and Composition are subset of association meaning they are specific cases of association.
- In both Aggregation and Composition object of one class owns object of another class.
- Aggregation implies a relationship where child can exist independent of parent.
- e.g: Class (Parent) and Student(Child). Delete the class and students still exist.
- e.g: Car(Parent) and Engine(child), Wheel(child). All three can exist independent of each other.
- Composition implies a relationship where the child cannot be exist independent of parent.
References:
1. https://www.guru99.com/association-aggregation-composition-difference.html
2. https://www.visual-paradigm.com/guide/uml-unified-modeling-language/uml-aggregation-vs-composition/
2. https://www.visual-paradigm.com/guide/uml-unified-modeling-language/uml-aggregation-vs-composition/
-Mayank
Comments
Post a Comment