Object-Oriented Programming - What’s It All About - Pdf 63

Part IV
Object-Oriented
Programming
16_597043 pt04.qxd 9/20/05 2:03 PM Page 211
In this part . . .
O
bject-oriented programming is the most hyped term
in the programming world — dot-com and business-
to-business e-commerce eclipsed it for a year or two, but
their high-flying fortunes have ’er, subsided, since the
dot-com crash of 2001.
C++ claims to be object-oriented — that’s what differenti-
ated it from good ol’ C. Java is definitely object-oriented,
as are a hundred or so other languages that were invented
during the last ten years. But what is object-oriented? Do I
have it? Can I get it? Do I want it?
Part IV demonstrates the features of C# that make it
object-oriented to the core. Not only will you be program-
ming objects, but you’ll also take possession of the keys
to powerful, flexible program designs — all right here in
Part IV!
16_597043 pt04.qxd 9/20/05 2:03 PM Page 212
Chapter 10
Object-Oriented Programming —
What’s It All About?
In This Chapter

Making nachos

Reviewing the basics of object-oriented programming


in your life. To reduce the number of things that you deal with, you work at a
certain level of detail. In object-oriented (OO) computerese, the level of detail
at which you are working is called the level of abstraction. To introduce
another OO term while I have the chance, I abstract away the details of the
microwave’s innards.
Happily, computer scientists — and thousands of geeks — have invented object
orientation and numerous other concepts that reduce the level of complexity
at which programmers have to work. Using powerful abstractions makes the
job simpler and far less error-prone than it used to be. In a sense, that’s what
the past half century or so of computing progress has been about: managing
ever more complex concepts and structures with ever less errors.
When I’m working on nachos, I view my microwave oven as a box. (As I’m trying
to knock out a snack, I can’t worry about the innards of the microwave oven
and still follow the Cowboys on the tube.) As long as I use the microwave only
through its interface (the keypad), nothing I can do should cause the microwave
to enter an inconsistent state and crash or, worse, turn my nachos — or my
house — into a blackened, flaming mass.
Preparing functional nachos
Suppose I were to ask my son to write an algorithm for how Dad makes
nachos. After he understood what I wanted, he would probably write, “Open
a can of beans, grate some cheese, cut the jalapeños,” and so on. When he
came to the part about microwaving the concoction, he would write some-
thing like, “Cook in the microwave for five minutes” (on a good day).
That description is straightforward and complete. But it’s not the way a func-
tional programmer would code a program to make nachos. Functional pro-
grammers live in a world devoid of objects such as microwave ovens and
214
Part IV: Object-Oriented Programming
17_597043 ch10.qxd 9/20/05 2:04 PM Page 214
other appliances. They tend to worry about flow charts with their myriad

my son, “What’s a microwave?” he would probably say, “It’s an oven that. . . .”
If I then asked, “What’s an oven?” he might reply, “It’s a kitchen appliance
that. . . .” If I then asked “What’s a kitchen appliance?” he would probably say,
“Why are you asking so many stupid questions?”
215
Chapter 10: Object-Oriented Programming — What’s It All About?
17_597043 ch10.qxd 9/20/05 2:04 PM Page 215


Nhờ tải bản gốc
Music ♫

Copyright: Tài liệu đại học © DMCA.com Protection Status