chapter four

4 Patterns for infrastructure dependencies

 

This chapter covers

  • Writing loosely coupled infrastructure modules using dependency patterns
  • Identifying ways to decouple infrastructure dependencies
  • Recognizing common infrastructure use cases for dependency patterns

An infrastructure system involves a set of resources that depend on each other. For example, a server depends on the existence of a network. How do you know the network exists before creating a server? You can express this with an infrastructure dependency, a relationship in which an infrastructure resource depends on attributes from other resources.

You can easily express the server’s dependency on the network by hard-coding the network identifier. However, hard-coding more tightly binds the dependency between server and network. Any time you change the network, you must update the hard-coded dependency. In Chapter 2, I raised the need to parameterize dependencies to promote reproducibility and evolvability. Passing the network identifier as a variable better decouples the server and network. A variable works between resources in a module, but how can you express dependencies between modules?

4.1 Unidirectional relationships

4.2 Dependency injection

4.2.1 Inversion of Control

4.2.2 Dependency inversion

4.2.3 Applying dependency injection

4.3 Facade

4.4 Adapter

4.5 Mediator

4.6 Choosing a pattern

4.7 Summary