Tuesday, November 13, 2018

For Any Pattern: "Does This Help Me Couple to an Higher-Level Abstraction?"

A sign indicating the steps to use a gas pump: insert dinosaur, age 100,000,000 years, refine gas, fill car.

One of the things that design patterns thinking is supposed to help you do is elevate the level of abstraction in your code. That doesn't just mean "write more interfaces" or "use ore abstract classes/protocols".

What it means is try to move the points of coupling away from the metal. The more a coupling point is about implementation details, the less useful it is and the shorter is helpful life will be. That is especially true an high-traffic interface but, really, it's true for the surface area of any piece of code.

So, if you are considering a design pattern and aren't quite sure if it applies to your situation, ask yourself this question:
"Does this help me couple to an higher-level abstraction?"
If applying the design pattern will make the interfaces (not the keyword interface, the English word "interface") a little more about "what" and a little less about "how", you might be on to something. If it cuts the other way, you may want to reconsider.