Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Association vs Dependency

 
Rabin Singh
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Reading from different posts from this site what I understood
that association is more stronger than dependency.

ClassA has association with ClassB -- if ClassB is instantiated by ClassA.
ClassA has dependency with ClassB -- if ClassB is passed as parameter in
a method or returned as parameter from a method call.


Now consider a case:

Client is using three classes atabase, Model, Element.

Client instantiates Database object, using the Database object gets
reference of Model object and after that calls method on Model object
to get Element. On the Element object client further calls method to
get the element inside the Element object.

In this case, I think relationship should be:
Client ---->(Association)-->Database
Client ---->(Dependency)--->Model
Client---->(Dependency)--->Element


But, I am reading a book, in this book all relationships has been shown
as association from the client.
Client ---->(Association)-->Database
Client ---->(Association)--->Model
Client---->(Association)--->Element


I would appreciate for any input.

Thanks
 
Dan Drillich
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Martin Fowler says in UML Distilled:

Many UML relationships imply a dependency. The navigable association from Order to Customer in Figure 3.1 means that Order is dependent on Customer. A subclass is dependant on its superclass but not vice versa.


Regards,
Dan
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic