• Networking
  • Programming
  • DBMS
  • Operating System
  • Internet
  • Hardware
  • Software

Tech Differences

Know the Technical Differences

Difference Between Aggregation and Composition

Aggregation vs CompositionAggregation and composition are the types of Association. The primary difference between aggregation and composition is that aggregation implicit a relationship where the child can exist independently of the parent. On the other hand, composition insinuates a relationship where the child cannot exist independent of the parent.

Object-Oriented programming is a common paradigm which is used in software development. The object is an instance of a class which are created by classes. The objects collaborate with each other through Links. Links are the physical and conceptual connection exists between objects. A collection of links having similar structure and semantics is described as an association.

Content: Aggregation Vs Composition

    1. Comparison Chart
    2. Definition
    3. Key Differences
    4. Conclusion

Comparison Chart

Basis for comparisonAggregationComposition
BasicIn aggregation there exhibit a relationship where a child can exist independently of the parent.In composition the cannot exist independently of the parent.
Type of relationship"has a""part of"
Association typeWeak associationStrong association
UML design symbolRepresented by a hollow diamond next to assembly class.Represented by a solid diamond next to assembly class.
FunctionThe deletion of assembly doesn't affect its parts.If the owning class object is deleted, it could significantly affect the containing class object.

Definition of Aggregation

Aggregation can be defined as a relationship with an assembly class to constituent class. The relationship between two objects can be represented by drawing a line segment in UML (Unified Modelling Language).Aggregation Aggregation is also used to specify the multiplicity of objects such as one-to-one, one-to-many and many-to-many. When an object of class X is associated with a single object of class Y, in that case there exist one-to-one relationship. Similarly, if a single object of a class is associated with multiple objects of a class, then this relationship is referred to as one-to-many.

For example, a car consists of wheels, engine, gearbox, steering, main body, etc. A car is an assembly, and the other parts are its constituents. Car to wheels is one aggregation, car to engines is another aggregation, and so on. Each individual pairing is defined to specify the multiplicity of each constituent part within the assembly as an outcome the number of objects can also be depicted.

The aggregation is a type of association which describes a “has a” type of relationship between the objects. For instance, a car “has a” gearbox, and a car “has an” engine. For the one-to-many relationship, an example is a car “has” many wheels.

Definition of Composition

The composition is also a type of association but a more restrictive form. It is represented in UML by a tiny solid diamond adjacent to the assembly class. CompositionIn this type of association, the constituent part can be linked to at most one assembly. Additionally, when a constituent part collaborates with assembly, it will have the concurrent lifetime with the assembly.

Thus, composition signifies ownership of the constituent part of the whole. This would ultimately increase the convenience for the programming. The composition can trigger the deletion of the constituent object by the deletion of an assembly object.

The composition describes a “part of” relationship. For example, a leaf is a part of a tree, if the tree is destroyed, then leaves are must be destroyed.

Key Differences Between Aggregation and Composition

  1. Aggregation indicates a relationship where a child and parent entities can exist independently. As against, in composition, the child entity is dependent on the parent.
  2. In aggregation there exist a “has a” relationship whereas in composition there is a “part of” relationship between the assembly and constituent class objects.
  3. Aggregation is weak association while the composition is a strong association because it has more constraints.
  4. In UML design the aggregation is described by a hollow diamond. In contrast, the composition is pictured by a solid diamond.

Conclusion

In aggregation, the constituent parts have the independent existence and can be shared or reassigned to aggregates or its assembly. On the other hand, in composition, the constituent part belongs to exactly one assembly or aggregate. Furthermore, the part is created when the aggregate is formed, and the part is destroyed when the aggregate is destroyed.

Related Differences:

  1. Difference Between Aggregation and Association
  2. Difference Between fork() and vfork()
  3. Difference Between Single and Multiple Inheritance
  4. Difference Between Link and Association
  5. Difference Between Thread Class and Runnable Interface in Java

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Top 10 Differences

  • Difference Between OLTP and OLAP
  • Difference Between while and do-while Loop
  • Difference Between Guided and Unguided Media
  • Difference Between Preemptive and Non-Preemptive Scheduling in OS
  • Difference Between LAN, MAN and WAN
  • Difference Between if-else and switch
  • Difference Between dispose() and finalize() in C#
  • Difference Between for and while loop
  • Difference Between View and Materialized View
  • Difference Between Server-side Scripting and Client-side Scripting

Recent Addition

  • Difference Between Unit Testing and Integration Testing
  • 4G Vs 5G
  • Raster Vs Vector Images
  • JPEG Vs TIFF
  • RJ11 Vs RJ12

Categories

  • DBMS
  • Hardware
  • Internet
  • Networking
  • Operating System
  • Programming
  • Software

Copyright © 2023 · Tech Differences · Contact Us · About Us · Privacy