Abstraction—Extracting Out the Essential Characteristics of a Thing
Object-oriented programming starts with object-oriented design. And object-oriented design starts
with abstraction.
What's an "object"? Using our new-found skill of "abstraction", consider the similarities between real-
world objects, say, a car and a software object. The attributes they share are shown in Table 11-2.
Software Dogma
The Key Idea: Abstraction
Abstraction is the notion of looking at a group of "somethings" (such as cars, invoices, or
executing computer programs) and realizing that they have common themes. You can then
ignore the unimportant differences and just record the key data items that characterize the
thing (e.g., license number, amount due, or address space boundaries). When you do this, it
is called "abstraction", and the types of data that you store are "abstract data types".
Abstraction sounds like a tough mathematical concept, but don't be fooled—it's actually a
simplification.
Table 11-2. Abstraction Example
Automobile Example Object Characteristic Software example: A Sorting
Program
"Car" Has a name for the whole
thing"sort"Input: fuel & oilOutput: transportationWell-defined inputs and
outputsInput: an unordered fileOutput: a file of ordered records
Engine, transmission, pumps, etc. Composed of smaller self-
contained objectsModules, header files, functions,
data structures
There are many cars and many
different types of carsCan have many instantiations
of the objectThe implementation should allow
several users to sort at once, for
example, not rely on one global
temporary working space.
The fuel pump doesn't rely on or
affect the windshield washerThose smaller, self-contained
objects don't interact except
through well-defined
interfacesThe routine to read records should be
independent of the key comparison
routine.Advancing the timing is not a
normal driving task, so there is
no control accessible to the driver
that directly achieves this.Can't directly manipulate, or
even see, the implementation
detailsThe user should not need to know or
be able to take advantage of the
specific sort algorithm used
(quicksort, heapsort, shellsort, etc.)
Can fit a larger engine without
changing the driver's controlsCan change the
implementation withoutThe implementor should be able to
substitute a better sort algorithm