QJ.NET | Videos | Forums | iPhone | MMORPG | Nintendo DS | Wii | PlayStation 3 | PSP | Xbox 360 | PC | Downloads | Contact Us
Forums | Gaming News | Videos | Downloads | Today's Posts | Mark Forums Read | Chat | FAQ | Members List | Contact

QJ.net Game Discussion - PSP, Xbox, Wii, PS3, PSP Homebrew, and PSP Guides

Go Back   QJ.net Game Discussion - PSP, Xbox, Wii, PS3, PSP Homebrew, and PSP Guides > Developers Corner > PSP Development, Hacks, and Homebrew > PSP Development Forum
The above video goes away if you are a member and logged in, so log in now!

[C++] OOP/microwave oven

This is a discussion on [C++] OOP/microwave oven within the PSP Development Forum forums, part of the PSP Development, Hacks, and Homebrew category; Hello, I recently purchested "C++ for Dummies" and while reading, I finally was able to comprehend what Object Oriented Programming ...

Reply
 
LinkBack Thread Tools
Old 05-28-2007, 03:49 PM   #1

Developer in Making...
 
BlackShark's Avatar
 
Join Date: Oct 2006
Location: Pimp'en in the US F#cking A!!!
Posts: 1,254
Trader Feedback: 0
Default [C++] OOP/microwave oven

Hello, I recently purchested "C++ for Dummies" and while reading, I finally was able to comprehend what Object Oriented Programming was. It gave me a great example and was pretty n00b friendly. Stephen Randy Davis calls it the Abstracting Microwave Ovens. This next part is from Chapter 11 in "C++ for Dummies"
Spoiler for Microwave oven:

Object-Oriented Programming

In This Chapter
  • Making nachos
  • Overview of object-oriented programming
  • Introduction to abstraction and classification
  • Why is object-oriented programming important?
Okay, you've waited long enough. What, exactly, is object-oriented programming? Object-oriented programming, or OOP as those in the know prefer to call it, relies on two principles you learned before you ever got out of Pampers: abstraction and classification. To explain, let me tell you a little story.

Abstraction and Microwave Ovens


Sometimes when my son and I are watching football, I whip up a terribly unhealthy batch of nachos. I dump some chips on a plate, throw on some beans, cheese, and lots of jalapeños, and nuke the whole mess in the microwave oven for 5 minutes.
To use my microwave, I open the door, throw the stuff in, and punch a few buttons on the front. After a few minutes, the nachos are done. (I try not to stand in front of the microwave while it's working lest my eyes start glowing in the dark.)
Now think for a minute about all the things I don't do to use my microwave:
  • I don't rewire or change anything inside the microwave to get it to work. The microwave has an interface -- the front panel with all the buttons and the little time display -- that lets me do everything I need.
  • I don't have to reprogram the software used to drive the little processor inside my microwave, even if I cooked a different dish the last time I used the microwave.
  • I don't look inside the case of my microwave.
  • Even if I were a microwave designer and knew all about the inner workings of a microwave, including its software, I would still use it to heat my nachos without thinking about all that stuff.
These are not profound observations. You can think about only so much at one time. To reduce the number of things that you must 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 internals.
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), there should be nothing I can do to cause the microwave to enter an inconsistent state and crash or, worse, turn my nachos into a blackened, flaming mass.
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 it came to the part about microwaving the concoction, he would write something like "cook in the microwave for 5 minutes."
That description is straightforward and complete. But it's not the way a functional programmer would code a program to make nachos. Functional programmers live in a world devoid of objects, such as microwave ovens and other appliances. They tend to worry about flow charts with their myriad functional paths. In a functional solution to the nachos problem, the flow of control would pass through my finger to the front panel and then to the internals of the microwave. Pretty soon, flow would be wiggling around through complex logic paths about how long to turn on the microwave tube and whether to sound the "come and get it" tone.
In a world like this, it's difficult to think in terms of levels of abstraction. There are no objects, no abstractions behind which to hide inherent complexity.
Object-oriented nachos

In an object-oriented approach to making nachos, I would first identify the types of objects in the problem: chips, beans, cheese, and an oven. Then I would begin the task of modeling these objects in software, without regard to the details of how they will be used in the final program.
While I am doing this, I'm said to be working (and thinking) at the level of the basic objects. I need to think about making a useful oven, but I don't have to think about the logical process of making nachos yet. After all, the microwave designers didn't think about the specific problem of my making a snack. Rather, they set about the problem of designing and building a useful microwave.
After the objects I need have been successfully coded and tested, I can ratchet up to the next level of abstraction. I can start thinking at the nacho-making level, rather than the microwave-making level. At this point, I can pretty much translate my son's instructions directly into C++ code.

Classification and Microwave Ovens


Critical to the concept of abstraction is that of classification. If I were to ask 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?")
The answers my son gave in my example questioning stem from his understanding of our particular microwave as an example of the type of things called microwave ovens. In addition, my son sees microwave ovens as just a special type of oven, which is in turn a special type of kitchen appliance.

In object-oriented computerese, my microwave is an instance of the class microwave. The class microwave is a subclass of the class oven, and the class oven is a subclass of the class kitchen appliances.
Humans classify. Everything about our world is ordered into taxonomies. We do this to reduce the number of things we have to remember. Take, for example, the first time you saw a Saturn automobile. The advertisement called the Saturn "revolutionary, the likes of which have never been seen." But you and I know that that just isn't so. I like the looks of the Saturn, but hey, it's a car. As such, it shares all of (or at least most of) the properties of other cars. It has a steering wheel, seats, a motor, brakes, and so on. I bet I could even drive one without help.
I don't have to clutter my limited storage with all the things that a Saturn has in common with other cars. All I have to remember is "a Saturn is a car that..." and tack on those few things that are unique to a Saturn. I can go further. Cars are a subclass of wheeled vehicles, of which there are other members, such as trucks and pickups. Maybe wheeled vehicles are a subclass of vehicles, which include boats and planes. And on and on and on.

Why Classify?


True to form, one of the important questions I ask in this book is "Why?" Why do we want to classify? It sounds like a lot of trouble. (Besides, I've been programming the functional way for so long. Why do I need to change now?)
It may seem easier to design and build a microwave oven specifically for this one problem, rather than build a separate, more generic oven object. Suppose, for example, that I want to build a microwave to cook nachos and nachos only. There would be no need to put a front panel on it, other than a START button. I always cook nachos the same amount of time. I could dispense with all that DEFROST and TEMP COOK nonsense. It would need to hold only one flat little plate. Three cubic feet of space would be wasted on nachos.
For that matter, I can dispense with the concept of "microwave oven" altogether. All I really need is the guts of the oven. Then, in the recipe, I put the instructions to make it work: "Put nachos in the box. Connect the red wire to the black wire. Notice a slight hum. Try not to stand too close if you intend to have children." Stuff like that.
But the functional approach has some problems:
  • Too complex. I don't want the details of oven building mixed into the details of nacho building. If I can't define the objects and pull them out of the morass of details to deal with separately, I must deal with all the complexities of the problem at the same time.
  • Not flexible. Someday I may need to replace the microwave oven with some other type of oven. I should be able to do so as long as its interface is the same. Without being clearly delineated and developed separately, it becomes impossible to remove an object type cleanly and replace it with another.
  • Not reusable. Ovens are used to make lots of different dishes. I don't want to create a new oven every time I encounter a new recipe. Having solved a problem once, it would be nice to be able to reuse the solution in future programs.

Hope this helps you as much as it did me
__________________
The Wentire Worls in two Sectors....
When did I get dev statz?
Spoiler for my PSP homebrewReleases:
Ace of Space V1|PvP Pong Online|PvP Pong v3 | 3.03 BlackShark Custom Firmware
(PvP Pong DL'ed well over 2403 times combined! get yours now!)
Spoiler for Great Quotes:

"No Snowflake in an Avalanche ever feels responsible....." - Fortune Cookie.
BlackShark is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 05-28-2007, 04:18 PM   #2

Developer
 
yaustar's Avatar
 
Join Date: Jun 2006
Location: UK
Posts: 2,317
Trader Feedback: 0
Default

It isn't just me, right? It looks like the author is trying to get across the concepts of classes, inheritance, multiple inheritance and interface classes in one go? It is difficult to see without the code.

Not a bad job though at explaining a complex subject though.
yaustar is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 05-28-2007, 04:55 PM   #3
 
ZereoX's Avatar
 
Join Date: Jan 2006
Posts: 871
Trader Feedback: 0
Default

Nice. but i don't think the author would like his stop posted on a forum for free?
__________________
Free Prizes at [url=http://www.prizerebel.com/index.php?r=189687]Prizerebel[/url] Join us!
I already got [b]11[/b] Gifts. Ask me for details or proof.
ZereoX is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 05-28-2007, 05:35 PM   #4

Developer in Making...
 
BlackShark's Avatar
 
Join Date: Oct 2006
Location: Pimp'en in the US F#cking A!!!
Posts: 1,254
Trader Feedback: 0
Default

well actuelly, I googled the book, and this chapter more specifically and was plainly available at barns and Nobles .com,
http://search.barnesandnoble.com/boo...ayonly=EXC&z=y
__________________
The Wentire Worls in two Sectors....
When did I get dev statz?
Spoiler for my PSP homebrewReleases:
Ace of Space V1|PvP Pong Online|PvP Pong v3 | 3.03 BlackShark Custom Firmware
(PvP Pong DL'ed well over 2403 times combined! get yours now!)
Spoiler for Great Quotes:

"No Snowflake in an Avalanche ever feels responsible....." - Fortune Cookie.
BlackShark is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 05-28-2007, 06:14 PM   #5
Art

Bush Programmer
 
Art's Avatar
 
Join Date: Nov 2005
Posts: 3,557
Trader Feedback: 0
Default

Damn, now I've got to rewrite most every program I've ever written.. see ya in a few years.

[edit] 'cept for the X-Flash credits demo, it's plug & play!
Art is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Tags
oop or microwave , oven

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off



All times are GMT -8. The time now is 06:50 PM.



Use of this Web site constitutes acceptance of the TERMS & CONDITIONS and PRIVACY POLICY
Copyright © 2009, QJ.NET. All Rights Reserved.
Contact Us