11.07.2015 Views

tYSR20

tYSR20

tYSR20

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

158Part III: Introduction to Classes I don’t look inside my microwave’s case. Even if I were a microwave designer and knew all about the inner workingsof a microwave, including its software, I would still use it to heat mynachos without thinking about all that stuff.These are not profound observations. You can deal with only so much stressin your life. To reduce the number of things that you deal with, you work at acertain level of detail. In object-oriented (OO) computerese, the level of detailat which you are working is called the level of abstraction. To introduceanother OO term while I have the chance, I abstract away the details of themicrowave’s innards.When I’m working on nachos, I view my microwave oven as a box. (As I’mtrying to knock out a snack, I can’t worry about the innards of the microwaveoven and still follow the Cowboys on the tube.) As long as I operate themicrowave only through its interface (the keypad), there should be nothingI can do to Cause the microwave to enter an inconsistent state and crash. Turn my nachos into a blackened, flaming mass. Burst into flames!Preparing functional nachosSuppose that I were to ask my son to write an algorithm for how Dad makesnachos. After he understood what I wanted, he would probably write “open acan of beans, grate some cheese, cut the jalapeños,” and so on. When it cameto the part about microwaving the concoction, he would write something like“cook in the microwave for five minutes.”That description is straightforward and complete. But it’s not the way a functionalprogrammer would code a program to make nachos. Functional programmerslive in a world devoid of objects such as microwave ovens andother appliances. They tend to worry about flow charts with their myriadfunctional paths. In a functional solution to the nachos problem, the flow ofcontrol would pass through my finger to the front panel and then to the internalsof the microwave. Pretty soon, flow would be wiggling around throughcomplex logic paths about how long to turn on the microwave tube andwhether to sound the “come and get it” tone.In a world like this, it’s difficult to think in terms of levels of abstraction. Thereare no objects, no abstractions behind which to hide inherent complexity.

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

Saved successfully!

Ooh no, something went wrong!