Skip to content
DiaGO

Dependency

The dashed arrow - one element temporarily uses another. The weakest, most common, and most under-drawn relationship in UML.

A dependency is the weakest relationship UML can express: one element needs another to get its work done, but only for a moment. It is drawn as a dashed line with an open (stick) arrowhead pointing at the element being depended on. UML names the two ends client and supplier — the client points at the supplier — and the formal semantics are blunt: a change to the supplier may require a change to the client. Nothing about structure, ownership, or lifetime is implied. That weakness is exactly why dependency is the most common relationship in real code and the most under-drawn one in diagrams.

What makes it a dependency

The dividing line between a dependency and an association is whether the client holds a lasting reference. If the supplier appears as a field, you have an association. If it appears only transiently — as a parameter type, a local variable, a return type, an object the client constructs, or the target of a static call — you have a dependency.

class OrderService {
  checkout(cart: Cart, gateway: PaymentGateway): Receipt {
    const total = cart.total();
    const confirmation = gateway.charge(total);
    return new Receipt(cart.id, confirmation);
  }
}

OrderService touches three other classes and stores none of them. Cart and PaymentGateway arrive as parameters and die with the call; Receipt is constructed and handed back. There is no field, so there is no association anywhere in this snippet. On a class diagram you would draw three dashed arrows leaving OrderService — written in text as OrderService ..> Cart, and so on — and zero solid lines. If a refactoring later promoted gateway to a constructor-injected field, that one arrow would harden into a solid association line, because the link would now outlive any single call.

DependencyAssociation
NotationDashed line, open arrowheadSolid line
Lifetime of the linkOne operation callLife of the object (a field)
Typical code shapeParameter, local, return type, new, static callField or property

Stereotypes name the flavor

Because "uses somehow" is vague, UML lets you label the dashed arrow with a stereotype in guillemets. The two you will actually meet are «use» — the generic form, so common that an unlabeled dependency is read as «use» by convention — and «create», meaning the client instantiates the supplier. «create» is worth drawing explicitly when the whole point of a class is which things it constructs, as in Factory Method: the arrow OrderFactory ..> Order labeled «create» says more than a page of prose. «call» and «instantiate» exist in the standard too, but industry usage rarely goes beyond the first two.

The arrow shows what breaks

Every dependency is coupling, and the arrow direction is a change-impact statement: it points from the thing that will break toward the thing that changed. OrderService ..> PaymentGateway means that renaming charge or altering its return type ripples into checkout, while OrderService can be rewritten freely without the gateway noticing. Read a diagram this way and the arrows stop being decoration — classes with many incoming dashed arrows are the ones you must keep stable, and classes with many outgoing ones are fragile.

This is also where the Dependency Inversion Principle earns its name. If PaymentGateway is a concrete Stripe client, the arrow runs from your domain toward volatile infrastructure. Make PaymentGateway an interface owned by the domain, and the concrete adapter now points at you via realization — the dependency arrow has been turned around without changing what the code does at runtime.

Draw few, draw deliberately

Here is the uncomfortable truth: by the formal definition, nearly every import in your codebase is a dependency. A diagram that drew them all would be an unreadable hairball, so the near-universal convention is to elide them. A class diagram is an argument, not an inventory — draw only the dependencies that carry design weight: the ones you would mention when explaining the design, the ones a reviewer should question, the ones that cross a layer or module boundary.

Reach for it

  • A class uses another only inside a method body and the coupling matters to the design
  • You want to show which factory or builder creates which product
  • A discussion of change impact needs the fragile direction made visible

Avoid it

  • The reference is stored in a field, which makes it an association instead
  • The link is already implied by an association or generalization you have drawn
  • You would end up transcribing every import in the module

Common mistakes

Solid where dashed belongs. A solid line claims a structural, lasting link; readers will go hunting for a field that does not exist. Keep the line style honest — it is the only thing distinguishing "borrows for one call" from "holds forever".

Reversed arrow. The arrow points at the supplier. Drawing PaymentGateway ..> OrderService claims the gateway knows about checkout — precisely backwards, and it inverts every change-impact conclusion a reader draws.

Drawing everything. Ten dashed arrows per class is not rigor, it is noise that buries the two arrows that matter. Elision is a convention, not a formal rule — but it is a convention every experienced reader expects.

Practice

Classify every relationship in this booking module, then draw the class diagram.

class BookingService {
  constructor(private repository: BookingRepository) {}
 
  book(room: Room, guest: Guest): Confirmation {
    const clash = this.repository.findOverlap(room, guest.stayDates());
    if (clash) throw new BookingConflictError(clash);
    const booking = Booking.create(room, guest);
    this.repository.save(booking);
    return new Confirmation(booking, Clock.now());
  }
}

BookingService touches seven types. Decide for each: association or dependency? Add «create» where it applies, get every arrow direction right, and finally decide which arrows you would keep in a diagram whose purpose is explaining the booking flow to a new teammate. (Check yourself: exactly one relationship here is an association.)