Design patterns thinking tells us to design to interfaces. This has nothing to do with the keyword interface that is available in a lot of languages. It's about the English word "interface".
You know... the "I" in "GUI" or "API".
With few exceptions, a needs-oriented interface represents a better contract for a class than a capabilities-oriented interface would. The better-ness of this contract manifests in two ways:
With few exceptions, a needs-oriented interface represents a better contract for a class than a capabilities-oriented interface would. The better-ness of this contract manifests in two ways:
- The coupling that forms will likely be long-lived and resilient to implementation-changes.
- It provides more context and drives better internal design decisions.
If you are considering whether or not a design pattern applies, try asking yourself if introducing the pattern will make the interfaces involved more about what should be accomplished or more about what should be done.
If the interfaces become more about what should be accomplished, that's a vote in favor.
If the interfaces trend toward a more imperative nature, you might want to reconsider.