Explore Topics
Dependency is the weakest UML relationship. It means one class temporarily uses another β typically as a method parameter, local variable, or return type. The dependent class does NOT store a reference as a field; the usage is confined to a single method scope. A change in the depended-upon class may affect the dependent class, because it relies on its interface. In UML, dependency is drawn as a dashed line with an open arrowhead pointing from the dependent class to the class it depends on.
- Weakest relationship β temporary usage, not permanent storage
- UML notation: dashed line with open arrowhead (- - - ->)
- Always directed: Class A depends on Class B (A - - -> B)
- Caused by method parameters, local variables, or return types
- No field reference β the object is used and released within method scope
- A change in Class B may break Class A (A depends on B's interface)
- β¦Keeps coupling minimal β classes are loosely connected
- β¦Easy to refactor since the relationship is not structural
- β¦Makes the "uses" intent explicit in the diagram
- β¦Good for utility and helper class relationships
- β³Often overlooked in diagrams because it is so lightweight
- β³Students frequently confuse dependency with association
- β³Too many dependencies on one class signals a design smell
- β³Hard to track in large codebases without tool support
Quiz
class Printer {
void print(Document doc) {
System.out.println(doc.getText());
}
}