Comparison
AbstractionvsProgramming to an interface
Abstraction
you stopped caring which of the three implementations you had, and the code got shorter in every caller.
A name for a capability that hides which particular thing provides it, so callers depend on the promise rather than the machinery. The word is used loosely for both the act — pulling a common shape out of two similar things — and the artefact, the interface or type that results. The cost is that every abstraction is a bet that the two things really are the same, and the ones that turn out wrong are more expensive to undo than the duplication they replaced.
Full entry →Programming to an interface
the type on the field is the interface, and the only line that names the concrete class is the one that builds it.
Declaring parameters, fields and return types in terms of what a collaborator can do rather than which class it is. It is the single sentence most of the catalogue is a consequence of: you cannot substitute, decorate, proxy or fake something your caller has hard-typed to a concrete class. In practice it earns its keep the first time you need a second implementation, and costs you an extra file every time you never do.
Full entry →