Reducing coupling 00:00:00 Make a prediction You will replace dependence on one printer implementation with a small receipt contract and detect hidden dependence on call order. If checkout formats the control commands of one printer, does plugging in a PDF output only require changing the output device? No. Printer-specific commands are embedded in checkout. Pass finished receipt data through a small output contract so each implementation can handle its own format. 00:00:29 Kites tied together Two kites tied by their tails pull each other off course whenever one turns. Give each pilot a clear tether and agree on the shared airspace, instead of tying the kites together. Components need a useful relationship, but only the required information should cross it. Hidden data formats and timing assumptions behave like extra strings. Coupling is how much one part must know about another. If OrderService builds a MySQLDatabase itself, it knows the class, how to create it, and when it lives. A change in any of these is a change in OrderService. A change in a tightly coupled program spreads: one column is renamed and five files, two teams and a release are involved. 00:01:15 Replace a receipt printer The sale service constructs a specific printer and formats that driver's commands. A new printer model now changes checkout code. Give the sale service a receipt output that accepts a finished receipt. Put driver commands behind one implementation. Run a test with a recorder as the output. Then substitute a PDF writer and compare receipt data. The sale service should not discover which output it received. Send one completed receipt to a printer, then send that same value to a PDF generator. Both can be tested without knowing how the order calculated tax. Passing the whole live order would let the outputs reach into unrelated fields and depend on future edits. 00:02:00 Spot hidden timing dependencies Two components exchange a shared object that must be populated in a particular order. Both compile independently, yet one breaks if called early. Replace the implicit sequence with a complete value or a clearly owned operation that enforces readiness. Set a breakpoint before the producer assigns the final total. A consumer relying on a call at just the right moment now sees a partial value. Publishing a complete receipt in one event makes readiness part of the contract and removes that hidden timing assumption. An interface can still leak the printer's control codes in every argument. The caller remains coupled even though the class names look cleaner. Stable, cheap value types can be passed directly; introducing a mockable service for every value creates unnecessary wiring. 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. 00:03:17 Try an interview follow-up How do you remove a hard wired database from forty classes? I would first protect the observable behaviour with tests. Then I would introduce a parameter whose default still uses the existing database, move one caller at a time and count the remaining direct imports. After the last migration, an import rule prevents the old dependency from spreading back into new code. A shipping screen parses a courier's tracking identifier to infer the service level. The courier changes its identifier format. Move that interpretation behind the courier integration, expose a named service level, and test both formats there. Now the screen can change independently of a vendor's encoding. 00:04:05 What to take with you Coupling is shared knowledge. Reduce it by sharing less (values instead of globals and flags), by sharing something stable (a small interface owned by its user), and by naming what is shared (a versioned event instead of a hidden table). Concrete classes meet in a composition root. Events are useful when many react or when time may pass, and they move the coupling into the message. Strong ties inside one module are cohesion and need no cure.