| Author |
Is that an association?
|
Costa Lamona
Greenhorn
Joined: Sep 17, 2006
Posts: 29
|
|
Hi if I am having a class1 that USE class2 without having instance variable pointing to class2, Is that Association? if class1 is having a instance variable which reference class2, while class1 never instantiated class2, is this Aggregation? if the previous case but class1 instantiated class2, is this composition. if you want to give me a link, that will be great but please answer the question first. Thanks
|
 |
Glen Ihrig
Greenhorn
Joined: Mar 12, 2007
Posts: 8
|
|
HI Costa, I am pretty new to this Composition, Association, Aggregation business myself, but after a lengthy study of "Head First OOA&D" and "The Object-Oriented Thought Process" and many internet articles, I have come the following conclusions regarding your questions:
if I am having a class1 that USE class2 without having instance variable pointing to class2, Is that Association?
Yes, while the classes are clearly associated, the instance of class2 is independent and may participate in relationships with other objects. This is true as long as class2 is instantiated elsewhere. It make no difference how class1 accesses class2.
if class1 is having a instance variable which reference class2, while class1 never instantiated class2, is this Aggregation?
No. This is still Association. Aggregation is not clearly defined beyond the UML symbol (white diamond). I (and notable others) believe you are best ignoring Aggregation, it doesn't really exist...
if the previous case but class1 instantiated class2, is this composition.
Yes. The key here is that class1 "owns" this instance of class2, the life span of these instances are the same. They are truly composed into a new whole. For more detail, and examples, see this thread Differing opinions are welcome, but please read the linked thread first. Regards, -Glen
|
 |
Ilja Preuss
author
Sheriff
Joined: Jul 11, 2001
Posts: 14112
|
|
|
http://faq.javaranch.com/java/AssociationVsAggregationVsComposition
|
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
|
 |
 |
|
|
subject: Is that an association?
|
|
|