The main difference between Aggregation and Generalization in UML is that Aggregation is an association of two objects that are connected with the “has a” relationship while Generalization is the process of forming a general class from multiple classes.
It is not possible to develop complex software at once. Therefore, it is necessary to understand what the software should perform before implementing them. Unified Modelling Language (UML) is a visual diagramming language that helps to model software. It is different and easier than programming languages such as Java and C++. As it provides a pictorial representation, even a non-technical person can learn and understand UML. Class and object diagram are two types of UML diagrams. Moreover, they describe the static view of the system. Aggregation and generalization are related to these diagrams.
Key Areas Covered
1. What is Aggregation in UML
– Definition, Functionality
2. What is Generalization in UML
– Definition, Functionality
3. Difference Between Aggregation and Generalization in UML
– Comparison of Key Differences
Key Terms
Aggregation, Generalization, Inheritance, UML
What is Aggregation in UML
An association represents the relationship between two objects. Aggregation is a type of association. In other words, it is a special case of association. When an object “has-a” another object, then we can consider it as an aggregation. Therefore, aggregation describes the “has a” relationship between objects.
Figure 1: Aggregation
The employee and address are linked with the “has a” relationship. An instance of the Address class can exist without an instance of the Employee. It is an aggregation. In UML, the diamond symbol represents an aggregation. The direction denotes which object contains the other object.
What is Generalization in UML
Generalization is associated with inheritance, which is the process of allowing classes to use the properties and methods of already existing classes. The existing class is the superclass while the new class is the subclass. Generalization combines multiple classes into a general class. Moreover, the superclass has the most general properties and methods. Subclasses can share those properties and methods. Subclasses can have specialized properties and methods. As a subclass is a type of super classes, the generalization represents “is a” relationship.
Figure 2: Generalization
Employee is the superclass. Permanent and Temporary Employee are subclasses whereas Employee is the generalized form of Permanent and Temporary Employee. On the other hand, Permanent and Temporary Employee are specialized forms of Employee. Employee has properties id, name, salary and the method display. The subclasses Permanent and Temporary Employee can also use these properties and methods. Furthermore, the subclasses have their own properties and methods. In UML, an arrow represents generalization.
Difference Between Aggregation and Generalization in UML
Definition
Aggregation is an association between two objects which describes the “has a” relationship while generalization is a mechanism for combining similar classes of objects into a single general class. Thus, this explains the main difference between aggregation and generalization in UML.
Relationship
Aggregation denotes “has a” relationship while Generalization denotes “is a” relationship.
UML representation
A diamond symbol represents an aggregation whereas an arrow symbol represents generalization. Hence, this further explains the difference between aggregation and generalization in UML.
Conclusion
In brief, Aggregation and Generalization are two concepts that can be represented in UML diagrams. The main difference between Aggregation and Generalization in UML is that Aggregation is an association of two objects that are connected with the “has a” relationship while Generalization is the process of forming a general class from multiple classes.
References:
1.“Association, Aggregation, Composition, Abstraction, Generalization, Realization, Dependency.” Javapapers, Available here.
ncG1vNJzZmiolZm2oq2NnKamZ6edrrV5yKxkraCVYrGqssWeqZ6mk5p6o7HTsJyepl2WtKi%2BxKCYraGfo3qiusNmnp6mlaeurbXZmquip55itq951KajaA%3D%3D