It's pretty strange to see all those answers about composition/aggregation/association. Who/What is the source of those notions?
https://www.geeksforgeeks.org/association-composition-aggregation-java/
wikipedia?!?! https://en.wikipedia.org/wiki/Object_composition
https://softwareengineering.stackexchange.com/questions/61376/aggregation-vs-composition
and finally my lovely stackoverflow (at least I glad that answers were not marked as verified) What is the difference between association, aggregation and composition? What is the difference between aggregation, composition and dependency?
There is a great book "Design Patterns" (GoF) https://en.wikipedia.org/wiki/Design_Patterns
It describes two most common techniques for reusing functionality in object-oriented systems: 1) class inheritance (is-a) 2) object composition (has-a)
"Object composition is an alternative to class inheritance. Here, new functionality is obtained by assembling or composing objects to get more complex functionality."
"Composition" is a very descriptive term to express relationship between objects unlike "Association". Why all those sources above use term "Composition" in the wrong way?!
Let's go further.
Objects could be composed in two ways: 1) Aggregation 2) Acquaintance
"Consider the distinction between object aggregation and acquaintance and how differently they manifest themselves at compile- and run-times. Aggregation implies that one object owns or is responsible for another object. Generally we speak of an object having or being part of another object. Aggregation implies that an aggregate object and its owner have identical lifetimes."
aggregate object and its owner have identical lifetimes!!!
"Acquaintance implies that an object merely knows of another object. Sometimes acquaintance is called "association" or the "using" relationship. Acquainted objects may request operations of each other, but they aren't responsible for each other. Acquaintance is a weaker relationship than aggregation and suggests much looser coupling between objects."
"It's easy to confuse aggregation and acquaintance, because they are often implemented in the same way. In Smalltalk, all variables are references to other objects. There's no distinction in the programming language between aggregation and acquaintance. In C++, aggregation can be implemented by defining member variables that are real instances, but it's more common to define them as pointers or references to instances. Acquaintance is implemented with pointers and references as well."
Guys, please, help me to figure out what's going on here...
Aucun commentaire:
Enregistrer un commentaire