jargon

Comparison

Abstract classvsProgramming to an interface

Abstract class

the base class does half the job and leaves a method for you to fill in, and you cannot instantiate it on its own.

A class that carries real implementation but is incomplete, declaring one or more methods that a subclass must supply. It sits between an interface, which has no implementation and can be implemented many times over, and a concrete class. Reach for it when the shared code is substantial and the variation is small; it buys reuse at the price of a single inheritance slot in most languages, which is the constraint that eventually forces the switch to composition.

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 →

Related comparisons