Updated April 5, 2023
Introduction to UML Aggregation vs Composition
Many varied types of notation are used in XML to represent association, composition, and aggregation. Here association is represented by a simple arrow, whereas a null diamond headed arrow denotes the aggregation, and a full diamond headed arrow is used to represent the composition. If any UML diagram should be constructed to signify any relationship between two classes of P and Q., If there is an association between P and Q, then it is represented by P -> Q. The composition and aggregation between any classes are also represented in a similar technique. The UML notations are also used to establish variable types of dependencies between the classes.
Head to Head Comparison between UML Aggregation vs Composition (Infographics)
Below are the top 8 comparisons between UML Aggregation vs Composition:
Key differences between UML Aggregation vs Composition
Let us discuss some key differences between UML Aggregation vs Composition in the following points:
1. Definition
- The aggregation and composition are based on the required classes of association. In the composition and aggregation is the object of single classes, representing the object of another class. The minor differs because the aggregation infers a relation where the child is present independent of the parent.
- For example, the parent and child are present in a class, and if the parent’s deletion doesn’t affect the operation of the child. But in composition, it infers that relationship where there is no child’s existence, and it does not rely on the parent class. The child depends on the parent and doesn’t exist separately without the parent.
2. Operation
- Aggregation is a section of association and its assortment of variable objects. It is used to denote any relationship. It is more specified to the association. It briefly explains the part of the entire relationship. The aggression includes only dual classes and represents a binary association. It is a type of relationship where the child is not based and dependent on the parent
- The composition is a section of segregation, and it denotes the part of the entire relationship. It portrays the relation and dependency between the child and parents. It can also be represented as components and their parts. It insists that if the component gets eliminated, its parts also will get discarded. Hence the composition is established within similar objects.
3. Examples
- The aggregation is explained with the best example. Let us take a car and wheel as an aggregation example. It is not possible for the car to move without a wheel. But the wheel is used as an individual object in other vehicles. So the object wheel signifies a meaning even without the presence of a car. Hence the relationship between wheel and car is termed as aggregation where the separated object wheel is not based on the parent object car.
- The best example of composition is the human body. The child is dependent on the parent, and if any parent object is discarded, the child object will get neglected. If the human dies, all the child classes such as legs and hands will have no meaning and are removed. So the child is dependent entirely on the parent.
- In aggregation, it is important to represent that the link doesn’t exist in any way of the class P that possesses the class Q. It doesn’t represent any parent-child relationship, whereas, in composition, the strong life cycle dependency is established between parent and child. The parent is deleted, and there is no presence of a child.
4. Object-Oriented Programming
- Here the object is dependent on others to utilize the functionality and services given by the object. The relation between two different objects is termed as an association in software design and is denoted with an arrow in UML.
- The aggregation and composition is a section of association between two different objects. But there are delicate variations between aggression and composition that is reflected by the notation of UML. The association between different objects is called composition. Here the one class possesses another class that doesn’t present meaningfully even if the parent class is eliminated.
5. Java
In terms of Java, the aggregation and composition are similar to object-oriented programming over the inheritance. The composition has an example of a car and an engine. Even if the car is removed, the engine is not useful as the engine’s model suits only to the particular car. In contrast, an aggressive relationship occurs between the wheel and the car. Because if the car is removed, the wheel can be used for any other vehicle.
Comparison Table of UML Aggregation vs Composition
The table below summarizes the comparisons between UML Aggregation vs Composition:
Attributes | Aggregation | Compression |
Definition | Aggregation is denoted by a straight line with one end of the null-diamonded arrow mark. | The composition is denoted by a straight line with a full diamonded arrow mark at one end. |
Dependency | It explains the section of the association relationship. | It explains the section of the aggregation relationship. |
Type of Relationship | The relationship established is very delicate. | The relationship established is definitely strong. |
Associate Objects | In aggregation, the related objects are present independently within the entire system. | In composition, the related objects are nor present within the entire system. |
Linked Objects | The linked objects present in the system are independent of other objects. | The linked objects present in the system are dependent on other objects. |
Deletion of Objects | Deletion of one element in the aggregation doesn’t impact the other components present in the associative section. | The deletion of one object impacts the presence of the other related objects in the compression. |
Examples | For the proper functioning of a car, the wheel is a mandatory element. But it doesn’t require the same wheel for the operation of the car. Even other wheels can be substituted. | If an image is placed in a document and that document gets deleted, the image cannot be found again or used. The image residing in the document also gets deleted simultaneously at the time of document deletion. |
Representation | P ——-<> Q | P ————<filled> Q |
Conclusion
The aggregation and composition in designing the software are owned and section-of. Suppose any object is a section of other objects. The relationship is coined as composition, and if the object possesses other objects without any dependency, it is aggregation.
Recommended Articles
This is a guide to UML Aggregation vs Composition. Here we discuss the UML Aggregation vs Composition top key differences with infographics and comparison table. You may also have a look at the following articles to learn more –