Win a copy of Head First Android this week in the Android forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Rob Spoor
  • Devaka Cooray
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Jj Roberts
  • Al Hobbs
  • Piet Souris

Is that an association?

 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
http://faq.javaranch.com/java/AssociationVsAggregationVsComposition
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic