Hi, 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.
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.
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.