AlgoViz

Reducing coupling

medium 40 min

Two parts are coupled when a change in one can force a change in the other.

Watch lesson4:37

Where it shows up

The same pattern appears across everyday software.

  • SLF4J

    A facade for logging in Java. Libraries call SLF4J, and the application chooses logback, log4j or another framework at deployment time.

  • Spring constructor injection

    The Spring documentation says the team generally advocates constructor injection, and that many constructor arguments are a sign of too many responsibilities.

  • Django signals

    A built in event mechanism whose own documentation warns about the appearance of loose coupling and recommends direct calls where possible.

  • Linux VFS

    The virtual file system is an abstraction in the kernel that lets different file system implementations coexist. Programs call `open` and `read` and do not know which one they use.

  • Kubernetes CRI

    A plugin interface through which the kubelet uses many container runtimes without recompiling.

  • JDBC drivers

    Code uses `java.sql` interfaces. `DriverManager` finds drivers through the service provider mechanism, so the vendor class need not be named.

  • Language Server Protocol

    Defines the protocol between an editor and a language server. m editors and n languages need m + n programs, not m x n.

  • Node.js EventEmitter

    Listeners are called synchronously. An `error` event without a listener throws and ends the process: even loose coupling has a contract.

  • Gradle api and implementation

    A library declares which of its dependencies are part of its interface and which are internal, so internals do not reach its users.