Reputation: 12184
If we consider a UML diagram where we have an object which contains a collection of objects of another class. What kind of relationship will be there,between both the classes.
Will it be aggregation or it will be Composition ?
The object having collection wont directly be having these objects, instead the collection will be holding them. but then in this case can we represent it as 1 is to Many, containment kind of relationship ?
I am very new to UML, I am sorry if It seems a total noob question.
Upvotes: 0
Views: 359
Reputation: 3268
Composition is a "part-of" relation like: every car has an engine and if engine is not exist, the car doesn't work. So relation between car and engine, is composition.
But aggregation is a "has-a" relation and in an aggregation, objects can exist independently of each other like car and radio.
So, If your relation is too strong, it is composition or not it is aggregation.
Upvotes: 0
Reputation: 4143
Less U.M.L., More Conceptual, Practical Answer
You have a first object, that contains another second object.
The second object its by itself a collection, that contains several object elements.
In a very technical, design or programming point of view, someone could think of the elements, not be related to the first object, but, to the second object as its container.
The first object its delegating the process of containning & managing objects to the second object.
I have use this case, several times, in Design & Programming. In many collection libraries, (arrays, lists, stacks), each item has a reference to the container.
I sometimes, add the reference to the first object itself, in each item.
So, you may think, of the main first object, & the collection object, as a single object.
Cheers.
Upvotes: 1