• 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

Difference between Dependency and Association

 
Ranch Hand
Posts: 413
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


Hi Guys,

What is the Difference between Dependency and Association

Thanks
 
Ranch Hand
Posts: 1936
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

The OMG UML specification (UML Superstructure Specification, v2.1.1, p. 64) states:

A dependency is a relationship that signifies that a single or a set of model elements requires other model elements for their specification or implementation. This means that the complete semantics of the depending elements is either semantically or structurally dependent on the definition of the supplier element(s).



The OMG UML specification (UML Superstructure Specification, v2.1.1, p. 41) states:

An association specifies a semantic relationship that can occur between typed instances. It has at least two ends represented by properties, each of which is connected to the type of the end. More than one end of the association may have the same type.

An end property of an association that is owned by an end class or that is a navigable owned end of the association indicates that the association is navigable from the opposite ends; otherwise, the association is not navigable from the opposite ends.

 
Ranch Hand
Posts: 198
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In Java terminology:

association : instance variable of a class of a type of the "other" associated class
dependency : method parameter, return value

Regards
 
Hong Anderson
Ranch Hand
Posts: 1936
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dependency means if class A call method of class B, that means class A has dependency to class B, if class B changes, class A might get impact.
About return value, I think it is Association. For method parameters, if you call methods of that parameters, it is Dependency.
 
Chaminda Amarasinghe
Ranch Hand
Posts: 413
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Here is my understanding about dependency, association, aggregation and composition

Dependency: If a Class A uses a Class B as a parameter or return type , A has a dependency on B.
Association: If a Class A has a reference (property) to Class B, then A associates B.
Aggregation & Composition. Both are type of Associations to represent Whole - Part. Make more sense in the context.

Strength of Relationship : Dep << Ass << Agg << Comp

Thanks
 
Hong Anderson
Ranch Hand
Posts: 1936
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
For me, regarding to strength of relationship, Dependency > Association (to be more specific > Composition).

"Depend" is more serious than "Associate", if you ask me.

Anyway, we should not compare Dependency and Association directly.

You can compare Dependency with Abstraction, Realization, InterfaceRealization, and Usage.
If class A implements interface B, if a method declared in B changes, it'll impact class A, this is an example of InterfaceRealization Dependency.
 
Chaminda Amarasinghe
Ranch Hand
Posts: 413
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Kengkaj

Anyway, we should not compare Dependency and Association directly.

You can compare Dependency with Abstraction, Realization, InterfaceRealization, and Usage.



Can you explain why?

Thanks
 
Hong Anderson
Ranch Hand
Posts: 1936
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Because they are different.

For example, we want to compare strength of tails of many kind of monkeys like Ape, Orangutan, Chimpanzee, etc. to see who has the strongest tail.

Do you think we can compare "strength of monkey tail" with human? Just because human is also animal, it does not mean that we can compare strength of tail of human and monkeys.
I hope you get what I mean.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic