4 Managing dependencies

This chapter covers

  • Reducing the effect of coupling in the class design
  • Depending on high-level, more stable code
  • Avoiding tightly coupled classes
  • Increasing flexibility and testability with dependency injection

In any software system, classes get together to deliver more extensive behavior. For example, a service class may depend on several repositories and entities to do its job. This means the service is coupled to these other classes.

We’ve discussed the problems of large classes and the advantages of smaller classes. On the one hand, having a class depend on other classes instead of doing everything alone is good. On the other hand, once a class delegates part of its task to another class, it has to “trust” the ...

Get Simple Object-Oriented Design now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.