It's not a secret anymore!*
The moose likes Architect Certification (SCEA/OCMJEA) and the fly likes Difference between Dependency and Association Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Architect Certification (SCEA/OCMJEA)
Bookmark "Difference between Dependency and Association" Watch "Difference between Dependency and Association" New topic
Author

Difference between Dependency and Association

Chaminda Amarasinghe
Ranch Hand

Joined: May 17, 2006
Posts: 402


Hi Guys,

What is the Difference between Dependency and Association

Thanks
Hong Anderson
Ranch Hand

Joined: Jul 05, 2005
Posts: 1936
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.


SCJA 1.0, SCJP 1.4, SCWCD 1.4, SCBCD 1.3, SCJP 5.0, SCEA 5, SCBCD 5; OCUP - Fundamental, Intermediate and Advanced; IBM Certified Solution Designer - OOAD, vUML 2; SpringSource Certified Spring Professional
Ronald Wouters
Ranch Hand

Joined: Apr 28, 2005
Posts: 190
In Java terminology:

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

Regards


Sun Certified Developer for the Java 2 Platform
Sun Certified Enterprise Architect for the Java Platform, Enterprise Edition 5
Hong Anderson
Ranch Hand

Joined: Jul 05, 2005
Posts: 1936
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

Joined: May 17, 2006
Posts: 402

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

Joined: Jul 05, 2005
Posts: 1936
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

Joined: May 17, 2006
Posts: 402
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

Joined: Jul 05, 2005
Posts: 1936
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Difference between Dependency and Association
 
Similar Threads
Association and dependency
Difference between Dependency and Association
dependency vs association
dependency vs association again???
difference between dependency and association