Class DIagram Aggregation
i came across this definition
Aggregation has two properties: antisymmetry, transitivit开发者_开发知识库y
What does it mean?
thanks
Aggregation is a type of object composition where object thing is part of another object. This is contrasted with ownership, where one object owns the other.
For example, a car is made out of many parts - engine, wheels, etc. The parts are aggregated into the car object.
But, in another example (which I found online) if a Person object has a car, that is not aggregation. The person owns it, but the car is not part of the person.
An important consequence of this difference is that when an object is destroyed, its aggregated parts should be destroyed as well. But objects that it owns, which are not part of it, should remain intact.
So, to the definitions:
Antisymmetry - I couldn't find an exact definition, but my intuition tells me that this means that two objects cannot be part of each other. Object A aggregates B, but never vice versa at the same time (unless A and B are equal, which is more about set theory than OOP). My arm is part of me, but I cannot be part of my arm.
Transitivity - It's just like transitivity in math. if A is part of B, and B is part of C, then A must be part of C. My hand is part of my arm, my arm is part of me, therefore my hand is part of me.
精彩评论