Difference between revisions of "Aggregation"

esse quam videri
Jump to: navigation, search
(Relevance)
 
(12 intermediate revisions by 3 users not shown)
Line 4: Line 4:
  
 
=Relevance=
 
=Relevance=
 +
In programming, there are different relationships that can be used between your objects. Aggregation, Composition and Association are all different types of these relationships.
  
 
=Explanation=
 
=Explanation=
Aggregation can be done by value or by reference. By value means that the two objects have the same lifespan and parts cannot be interchanged. By reference allows parts to be interchanged because the objects have been de-coupled. Another way to think of Aggregation is Object A “uses” Object B.
+
Aggregation can be done by value or by reference. By value means that the two objects have the same lifespan and parts cannot be interchanged. By reference allows parts to be interchanged because the objects have been de-coupled. Another way to think of Aggregation is Object A “has an” Object B.
  
 +
Composition is another form of aggregation, where the object is "part-of" another. This means, for the "part-of" object to exist, the other object also needs to exist. This is similar to a steering wheel or an engine to a car. If you were to get rid of the car, you would also get rid of the engine, steering wheel, and any other of its components. This is different to aggregation, which is more similar to a car and a child's car seat, where the child's seat is still part of the car, however, if you get rid of the car, the child seat will continue to exist.
 +
 +
[[File:AggregationVisual.jpg|512px]]
  
 
=Resources=
 
=Resources=
 +
https://atomicobject.com/resources/oo-programming/object-oriented-aggregation
 +
 +
https://softwareengineering.stackexchange.com/questions/61376/aggregation-vs-composition
  
== See also ==
 
  
  
  
==Notes==
 
  
  
==External Links==
 
  
  

Latest revision as of 14:30, 12 August 2019

Definition

In object-oriented programming, aggregation is a whole/ part relationship between objects or classes. Class aggregation can correspond to physical containment in a model, such as a car that has an engine, doors, and windows. Class aggregation can also correspond to abstract containment such as a club and members. This relationship does not imply ownership, however.

Relevance

In programming, there are different relationships that can be used between your objects. Aggregation, Composition and Association are all different types of these relationships.

Explanation

Aggregation can be done by value or by reference. By value means that the two objects have the same lifespan and parts cannot be interchanged. By reference allows parts to be interchanged because the objects have been de-coupled. Another way to think of Aggregation is Object A “has an” Object B.

Composition is another form of aggregation, where the object is "part-of" another. This means, for the "part-of" object to exist, the other object also needs to exist. This is similar to a steering wheel or an engine to a car. If you were to get rid of the car, you would also get rid of the engine, steering wheel, and any other of its components. This is different to aggregation, which is more similar to a car and a child's car seat, where the child's seat is still part of the car, however, if you get rid of the car, the child seat will continue to exist.

AggregationVisual.jpg

Resources

https://atomicobject.com/resources/oo-programming/object-oriented-aggregation

https://softwareengineering.stackexchange.com/questions/61376/aggregation-vs-composition