• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Excellent questions

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Let's assume class A object must be associated with class B.
The best way is to:
A) draw an association between the two classes
B)Pass class B refernce from the object creation parameter of A
Or do you suggest anything else?

 
Ranch Hand
Posts: 320
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
Personally I think the way you show this association is really dependant on the implementation. Is it an aggregation, dependency or even a construction?
Both your answer could be correct, it just "depends".

------------------
SOURCE CODE should be SURROUNDED by "code" tags.
Click here for an example
 
Ranch Hand
Posts: 1157
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Erum,
I agree with John on this.It depends on what is the actual requirement.
If you are speaking of the association between Order and OrderLineItem, you would expect the OrderLineItem to be managed by Order.The OrderLineItems is very specific to a particular Order instance, and if an Order is deleted all the corresponding OrderLineItems would be deleted.Hence, this would be a case of strong association also called composition, wherein Order would have one of its attributes as OrderLineItem (may be a Vector to hold all the lineitems).
On the other hand, consider a case of Employee and Department.The association between these two classes is not of the same type as Order and OrderLineItem.Unlike Order and OrderLineItem, you would expect the Department to exist even if a specific instance of an Employee is deleted. Most likely you would like to know which Employee works in which Department.So, we may have a method(operation) in Employee class, say inDepartment(Department dept), which return a boolean to suggest whether the present Employee instance is working in the passed Department reference.
I would like to mention, that in strict UML terms, the latter case is not a association but a dependency (shown by dotted line in Class Diagram artifact).
To sum up, it depends on what kind of associativity you are defining at the Design Level.The important thing to ask is whether you would want Object A to manage the life cycle of Object B.If yes, show that as a composition, other wise show it as a dependency.

Hope this helps,
Sandeep
SCJP2,OCSD(Oracle JDeveloper),OCED(Oracle Internet Platform)
reply
    Bookmark Topic Watch Topic
  • New Topic