04.01.2015 Views

Thinking in C++ 2nd ed Volume 1 Revision 6

Thinking in C++ 2nd ed Volume 1 Revision 6

Thinking in C++ 2nd ed Volume 1 Revision 6

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

abstraction of the underly<strong>in</strong>g mach<strong>in</strong>e. Many so-call<strong>ed</strong> “imperative”<br />

languages that follow<strong>ed</strong> (such as Fortran, BASIC, and C) were<br />

abstractions of assembly language. These languages are big<br />

improvements over assembly language, but their primary<br />

abstraction still requires you to th<strong>in</strong>k <strong>in</strong> terms of the structure of<br />

the computer rather than the structure of the problem you are<br />

try<strong>in</strong>g to solve. The programmer must establish the association<br />

between the mach<strong>in</strong>e model (<strong>in</strong> the “solution space,” which is the<br />

place where you’re model<strong>in</strong>g that problem, such as a computer) and<br />

the model of the problem that is actually be<strong>in</strong>g solv<strong>ed</strong> (<strong>in</strong> the<br />

“problem space,” which is the place where the problem actually<br />

exists). The effort requir<strong>ed</strong> to perform this mapp<strong>in</strong>g, and the fact<br />

that it is extr<strong>in</strong>sic to the programm<strong>in</strong>g language, produces<br />

programs that are difficult to write and expensive to ma<strong>in</strong>ta<strong>in</strong>, and<br />

as a side effect creat<strong>ed</strong> the entire “programm<strong>in</strong>g methods” <strong>in</strong>dustry.<br />

The alternative to model<strong>in</strong>g the mach<strong>in</strong>e is to model the problem<br />

you’re try<strong>in</strong>g to solve. Early languages such as LISP and APL chose<br />

particular views of the world (“all problems are ultimately lists” or<br />

“all problems are algorithmic”). PROLOG casts all problems <strong>in</strong>to<br />

cha<strong>in</strong>s of decisions. Languages have been creat<strong>ed</strong> for constra<strong>in</strong>tbas<strong>ed</strong><br />

programm<strong>in</strong>g and for programm<strong>in</strong>g exclusively by<br />

manipulat<strong>in</strong>g graphical symbols. (The latter prov<strong>ed</strong> to be too<br />

restrictive.) Each of these approaches is a good solution to the<br />

particular class of problem they’re design<strong>ed</strong> to solve, but when you<br />

step outside of that doma<strong>in</strong> they become awkward.<br />

The object-orient<strong>ed</strong> approach goes a step further by provid<strong>in</strong>g tools<br />

for the programmer to represent elements <strong>in</strong> the problem space.<br />

This representation is general enough that the programmer is not<br />

constra<strong>in</strong><strong>ed</strong> to any particular type of problem. We refer to the<br />

elements <strong>in</strong> the problem space and their representations <strong>in</strong> the<br />

solution space as “objects.” (Of course, you will also ne<strong>ed</strong> other<br />

objects that don’t have problem-space analogs.) The idea is that the<br />

program is allow<strong>ed</strong> to adapt itself to the l<strong>in</strong>go of the problem by<br />

add<strong>in</strong>g new types of objects, so when you read the code describ<strong>in</strong>g<br />

the solution, you’re read<strong>in</strong>g words that also express the problem.<br />

This is a more flexible and powerful language abstraction than what<br />

we’ve had before. Thus OOP allows you to describe the problem <strong>in</strong><br />

terms of the problem, rather than <strong>in</strong> terms of the computer where<br />

1: Introduction to Objects 41

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!