Markus
Markus

Reputation: 3627

Dependency relationship

I have a question on dependency relationship in a class diagram. Is it correct to show that a class has an attribute of an interface type by specifying a dependency relationship? Or this can be done with association only? I've read that a dependency relationship is used only for method's parameters or local variables.

Upvotes: 2

Views: 458

Answers (3)

Damien
Damien

Reputation: 2254

An association is just a particular form of dependency. So, to answer your question, yes it is correct (valid) to represent an association as a dependency, however using an association is more accurate.

In his book "UML Distilled", Martin Fowler defines dependencies like that:

A dependency exists between two elements if changes to the definition of one element [...] may cause changes to the other [...]. With classes, dependencies exist for various reasons: one class sends a message to another; one class has another as part of its data; one class mentions another as a parameter to an operation.

Upvotes: 2

UML GURU
UML GURU

Reputation: 1462

It is not forbidden in UML therefore it is allowed :-)

Upvotes: 0

pavanlimo
pavanlimo

Reputation: 4252

From Wikipedia

A dependency in the Unified Modeling Language exists between two defined elements if a change to the definition of one may result in a change to the other. In UML this is indicated by a dashed line pointing from the dependent (or client) to the independent (or supplier) element.

So per the definition, it makes sense to show that a class has an attribute of an interface type by specifying a dependency relationship. I'm not 100% sure though.

Upvotes: 0

Related Questions