liveBook · Manning

Dependency

As explained in Simple Object-Oriented Design: Create clean, maintainable applications

A dependency is a relationship in which one software component relies on another component whose changes may affect it.

A dependency exists when one component relies on another to deliver behavior. Dependencies are necessary for collaboration, but they also create coupling: a change or bug in one component can affect clients without their code changing. The maintenance goal is not zero dependencies; it is deliberate, limited dependencies that do not let complexity or change propagation escape control. section 4.0 section 1.2.3

Prefer dependencies on stable abstractions rather than volatile implementation details. Information hiding lets a component evolve internally while clients rely only on the minimum information they need. Before exposing or consuming an API detail, ask whether clients will be affected by refactoring it, whether it changes frequently, and whether a more stable interface can hide it. section 4.2 section 1.2.3

Control dependency growth with practical design checks:

  • Treat a class with many collaborators as a possible design problem; its interaction complexity and exposure to change both increase. section 4.3
  • When adding functionality, weigh expanding an existing unit against adding a linked class: one increases local complexity, while the other increases coupling. section 4.3
  • Break down units whose dependency sets have become too large, aiming to limit the scope of future changes. section 4.3
  • Avoid depending on details a client does not need; conceal volatile implementation choices behind a stable abstraction where possible. section 4.2

Containing a payment-library dependency

A payment gateway library may require its own PaymentDetails type and API calls. Instead of letting that external type spread through the domain, define an application-owned payment data structure and route calls through a PaymentGateway adapter. If the library changes, update the adapter rather than every caller. The wrapper can feel redundant, but it creates a boundary around code whose release cycle and breaking changes are outside your control. section 6.3

Dependency management is a tradeoff, not a rule to maximize separation at any cost. Delegating work to other classes is often preferable to making one class do everything, yet every added collaborator introduces trust, interaction, and potential ripple effects. Favor small units in both responsibility and dependency count, while choosing the simpler design that keeps likely changes contained. section 4.0 section 4.3

Figure 1.4 Dependency management and change propagation

Trace how direct and transitive dependencies can carry changes into a dependent class, including changes outside its immediate collaborators. section 1.2.3

Figure 6.4 The adapter prevents the library code from getting spread into the domain.

Inspect the adapter boundary that keeps third-party payment-library types and calls from spreading into domain code. section 6.3

How Simple Object-Oriented Design: Create clean, maintainable applications covers it

How deep it goes
Explains dependency risks, information hiding, class decomposition, and third-party wrappers without prescribing a universal architecture.
Examples
Uses Basket with DiscountRules, Product, Customer, and repositories, plus a payment gateway wrapped by an adapter.
What it assumes
Assumes object-oriented classes and collaboration, then develops dependency-management decisions through design examples.
What you can do after
Evaluate and reshape class and external-library dependencies to contain change and improve maintainability.
How it connects
Connects dependencies to coupling, information hiding, interfaces, abstractions, adapters, and testability.

Also explained in

Compare how 27 books explain dependency →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Simple Object-Oriented Design: Create clean, maintainable applications. The section links point to the parts of the book it draws on.