Skip to content
Low Level Design Mastery Logo
LowLevelDesign Mastery

Dependency

Temporary use - weakest relationship between classes.

Dependency is the weakest relationship where one class uses another temporarily. The dependent class doesn’t store a reference to the other class - it only uses it as a parameter, local variable, or return type.

Dependency represents:

  • “Uses temporarily” relationship
  • No ownership - doesn’t store reference
  • Temporary use - only during method execution
  • Weakest relationship - no coupling beyond method call
  • Temporary use - Only during method execution
  • No storage - Not stored as instance variable
  • Method parameters - Usually passed as parameters
  • Dashed arrow in UML diagrams
Diagram
FeatureDependencyAssociation
DurationTemporaryPersistent
StorageNot storedStored as reference
LifecycleNo couplingSome coupling
UML SymbolDashed arrowSolid arrow
ExampleOrder uses CalculatorTeacher has Courses

Use Dependency when:

  • Class uses another temporarily
  • Passing objects as method parameters
  • Using objects as local variables
  • You want minimal coupling
  • Relationship is not persistent
  • Objects are created externally

Examples:

  • Order uses Calculator (for calculation)
  • Order uses Printer (to print receipt)
  • ShoppingCart uses PaymentProcessor (to process payment)
  • Report uses Formatter (to format output)
  • Service uses Logger (to log messages)

💡 Time to Practice!

Now that you understand the concepts, put them into practice with our interactive playground. Build UML diagrams, write code, and get AI-powered feedback.

Browse All Problems