Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Association and Dependency

 
T Rai
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
anyone knows the distiction between these two? when do we need these two? and importantly, how do we implement these two relationships in codes? any examples for the clarification?
I would appreciate your help. Thanks.
 
Nicholas Cheung
Ranch Hand
Posts: 4982
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You might post your question at:
http://www.coderanch.com/forums/f-9/patterns

Nick
 
Lin Feng
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Association means two classes have relationship. For example Employees report to Manager , Students registered a Course etc... For example we
can have
class Employee
{
class Manager mDirectManager ;

}

Dependency means one class depends on another one. They do not have to be associated. The dependency can be a parameter type etc.

For example

Class AnyClass
{
public void anyMethod(Class AnyOtherClass b)
{
System.out.println(b.getName());
}

}

if the AnyOtherClass removed its getName() method , the AnyClass should be changed. Except in the anyMethod the AnyClass does not use AnyOtherClass.
This is an dependency.

Hope this help. You can find detail information about this from Apply UML and Patterns.

Thanks

Lin
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic