Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between association and dependency?

Tags:

uml

In a UML class diagram, what is the difference between an association relationship and a dependency relationship?

From what I know, an association is a stronger relationship than a dependency, but I'm not sure how it is stronger.

Any example would be more than welcome :)

like image 912
Charlie Avatar asked Aug 05 '09 02:08

Charlie


2 Answers

An association almost always implies that one object has the other object as a field/property/attribute (terminology differs).

A dependency typically (but not always) implies that an object accepts another object as a method parameter, instantiates, or uses another object. A dependency is very much implied by an association.

like image 95
Randolpho Avatar answered Sep 18 '22 11:09

Randolpho


In OOP terms:

Association --> A has-a C object (as a member variable)

Dependency --> A references B (as a method parameter or return type)

public class A {     private C c;     public void myMethod(B b) {         b.callMethod();     } } 

There is also a more detailed answer.

like image 39
Ahmad Abdelghany Avatar answered Sep 17 '22 11:09

Ahmad Abdelghany