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

association vs dependency

 
Ranch Hand
Posts: 3852
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please follow these two links:

https://coderanch.com/t/98345/patterns/Association-Composition-Aggregration

http://forum.java.sun.com/thread.jspa?threadID=485575&messageID=2288471

I am confused between association and dependency.



First link says, it's association. Second says, it's just dependency.

Please clear me.

Thanks.
 
Bartender
Posts: 2968
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
An association implies dependency.

At the code level a reference to another class or instance usually is at least an association.

The only way I can imagine a dependency in Java code that isn't an association is an unused object member or an unused method parameter. Once you start using methods on the object you are defining the semantics of the relationship at which point the relationship is at least an association.

Your example has a dependency (which isn't an association) because you are not using bar inside of Foo.do. The moment you call a method on bar inside of do() you are defining the semantics of the relationship between Foo and Bar - now there is an association between Foo and Bar.

Dependency is also used more as an 'aspect' rather than a full-blown concept. There are many types of dependencies that can adorn an inter-classifier relationship: access, binding, call, creation, derivation, instantiation, permission, realization, refinement, send, substitution, trace dependency, usage.
 
Ranch Hand
Posts: 214
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In UML a dependency means that a change in the definition of one of the dependent objects may result in a change to the other.

An association allows one object instance to allow another to act on its behalf (by sending a message from one to the other).

Dependencies can exist between other elements than classes. (Requirements, use cases, packages, etc.)

The word dependency is overloaded a little bit in current use in such idioms as "dependency injection" and "dependent objects". In a UML context I believe these are associations. (Not to suggest that we should start saying "association injection".)
 
Is that a spider in your hair? Here, threaten it with this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic