Wednesday, September 5, 2018

Control is the Goal with Coupling

The code qualities aren't all unconditionally good. Nor are they bad. They just are. The effects are good or bad but not the qualities, themselves.

Coupling is one of the greatest examples of this fact.

You can't set a goal of eradicating coupling because certain kinds of coupling are essential to software design. You can't set a goal of creating coupling because rampant coupling makes a system all but impossible to maintain.

What we want is exactly the right coupling with no coupling that doesn't meet our standard.

This means that what you really want to do with coupling is neither limitation (such as is the case with redundancy) nor promotion (as you would with encapsulation). Instead, you want control.

Control is the name of the game and there are a few instruments we use to maximize our control:

  • Encapsulation limits opportunity to accidentally create a connection that should not exist.
  • Expressive interfaces make it easier to create the connections that should exist.
  • Strong test-coverage make the effects of changing coupling more obvious.

Managing coupling is one of the first steps to establishing a sustainable design.