As programs become more complex, the advantages of OOPs increase because they are readily scalable. What does that mean? Well, OOPs provide options to more easily define what actions can be taken on a class of objects by a program. This increased ease makes it easier to make bigger and more complex programs. To illustrate this, have a look at the following example. If you wanted to add two numbers, say, 1 and 2, in an ordinary, non-object-oriented computer language like C (don't worry -- you don't need to know any C to follow this), you might write this:
This says,
Now, here's the same thing expressed in Smalltalk, which is a pure object-oriented language:
Wait a minute. Except for some minor notational differences, this looks exactly the same! Okay, it is the same, but the meaning is dramatically different. In Smalltalk, this says,
Hmm. This seems like a far more complicated way of accomplishing exactly the same thing! So why bother? The reason is that objects greatly simplify matters when the data get more complex. Suppose you wanted a data type called list, which is a list of names. In C, list would be defined as a structure. <definition of list structure data here>
Let's try to add these new a and b in the C language:
Guess what? This doesn't work. The C compiler will generate an error when it tries to compile this because it doesn't know what to do with a and b. C compilers just know how to add numbers. Period. But a and b are not numbers. One can do the same thing in Smalltalk, but this time, list is made a class, which is a subclass of the built-in Smalltalk class called "String":
The first two lines simply create List objects a and b from the given strings. This now works, because the list class was created with a method which specifically "knows" how to handle the message "+". For example, it might simply combine the argument with its own object by sticking them together with a comma separating them (this is done with a single line of Smalltalk). So c will have the new value:
Here's another example of a "+" message using more interesting objects. Click a, b, and c in turn to find out what they are (you'll need a WWW browser with support for "aiff" sounds):
Thanks to Terry Montlick for this example.
|
|
Visit An Area In OzEdweb | Technophile_City_(INFOTECH) | The_Time_Machine_(HISTORY) | The_Tree_House_(SOSE) | Lessons_Index | Assessment_Instruments | Maps | Power Point | Proforma | Links | Gallery | Games | Humour | Prizes | WebRings | Soapbox | Search_Engines | Site_ Map_ | |
| . |
|
.CLICK
ME TO VIEW FRAMES
ALL RIGHTS RESERVED
OZEDWEB-©-VIRTUAL
OZ |