Expert C Programming

(Jeff_L) #1

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 & oil

Output: transportation

Well-defined inputs and
outputs

Input: an unordered file

Output: a file of ordered records
Engine, transmission, pumps, etc. Composed of smaller self-
contained objects

Modules, header files, functions,
data structures
There are many cars and many
different types of cars

Can have many instantiations
of the object

The 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 washer

Those smaller, self-contained
objects don't interact except
through well-defined
interfaces

The 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
details

The 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 controls

Can change the
implementation without

The implementor should be able to
substitute a better sort algorithm
Free download pdf