Question: What is the difference between weak and strong aggregation in object modeling?
In the context of object-oriented modeling and design, the terms "weak aggregation" and "strong aggregation" pertain to specific types of relationships between objects, also known as "associations". These terms essentially describe the nature of the bond between the "whole" object and its "part" objects.
- Weak Aggregation (Shared Aggregation): This refers to an association where the lifecycle of the "part" object is not strictly dependent on the "whole" object. In other words, if the "whole" object is destroyed or removed, the "part" objects can continue to exist independently. They are not necessarily deleted or destroyed along with the whole. An example of this could be a "Classroom" object and "Student" objects - even if a particular classroom is no longer used, the students (parts) still exist and can be associated with other classrooms (wholes).
- Strong Aggregation (Composition): This refers to an association where the lifecycle of the "part" object is strictly tied to the "whole" object. If the "whole" object is destroyed or removed, all its associated "part" objects are also automatically deleted or destroyed. They cannot exist without the presence of the whole. An example could be a "House" object and "Room" objects - if a house (whole) is demolished, its rooms (parts) cease to exist.
In UML (Unified Modeling Language), these relationships are typically represented as follows:
Weak Aggregation is depicted by a hollow diamond at the "whole" end of the line connecting the objects.
Strong Aggregation is depicted by a filled diamond at the "whole" end of the line connecting the objects.
Remember, the use of weak or strong aggregation should be dictated by the specific rules of the domain being modeled. Selecting the right type of aggregation ensures that the object model correctly represents the real-world relationships between the entities.
In strong aggregation a part entity cannot exist without the containing whole entity in the whole-part relationship.
For example, university has multiple departments. This a composition relationship between the university and department entity. A department cannot exist on its own with out the university.
Composition is used for aggregations where the life span of the member object depends on the life span of the aggregate.
The aggregate not only has control over the behavior of the member, but also has control over the creation and destruction of the member. In other words, the member object cannot exist apart from the aggregate. This greater responsibility is why composition is sometimes referred to as strong aggregation. Composition is a subset of aggregation, just as aggregation is a subset of association.