The difference between Aggregation and Association in implementation

Ramy670 :

I have read a lot of theory regarding object relationshisps, and I am still having difficulty understanding how are association and aggregation seperated from implementaion point of view. In both cases you will have object B as a data member in object A, where it is present there as a reference,(unlike with composition where it exists there by value). So what is the difference between the two cases really? I have read somewhere that some Java gurus consider aggregation a solely abstract concept, a "placebo" case that can not be told apart (from association) from implementation/syntax point of view, is that right or have I missed something?

Czarnowr :

I agree that from the implementation point of view both association and aggregation look the same - like you mentioned, in both cases one of the objects is a data member in the other.

The way I understand this is that the implementation difference that you are asking about does not happen at the level of the object, but rather at the level of the application design:

  • If by implementation difference you understand the code itself (the way the object is placed within another), then there is no difference.

  • But if we extend the conversation to how the objects are used within the application, then we need to start looking at whether the objects are self sufficient or not, whether they can serve a unique, independent function or not. It is for you to decide whether this is still implementation

Edit -> additional explanation added below:

I might have not been clear enough - what I meant was that in this case the implementation could be considered on two levels:

  • the code that represents the object within the class (the field holding the reference to the object)

  • the wider code (how the object is used in other classes or how the dependencies between objects are represented)

Both of those could be understood as implementation, but on different levels of abstraction - the usage within the class is the same for both Aggregation and Composition, yet the way the object relationships are implemented across multiple classes would differ.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=328852&siteId=1
Recommended