[Tutor] definition question

Jeff Shannon jeff@ccvcorp.com
Mon Aug 4 15:34:02 EDT 2003


Kirk Bailey wrote:

> Sean 'Shaleh' Perry wrote:
>
>> Basically OOP is designed around nouns (objects) and verbs (methods).
>>
>> bob.kicks(jane) whereas the procedural guy thinks kick(bob, jane).
>>
> Hmmm!  bob.kick() is a instance of the superclass KICK, or of BOB? The 
> VERB is 'kick' of course. 


In this example, kick() is the verb, while bob (and presumably jane) are 
instances of some class.  We actually don't know what class bob is, nor 
does it matter.  We're presuming that bob knows how to kick, and that's 
all that's important.  Bob could be a person, or a horse, or a 
five-legged Rigellian land-squid -- as long as Bob knows how to respond 
to being told to kick(jane), it's all the same to us.  This is one of 
the advantages of OOP -- it makes it very easy if we determine later 
that Bob needs to change.

In a procedural world, when someone writes the function kick(bob, jane), 
he'll need to know about all the possible things that both Bob and Jane 
could be, and take every possible variation into account.  The problem 
here comes when it's discovered that an important possibility was left 
out -- at that point, kick() must be changed, and the new possibility 
factored in to the big list of possible combinations.  In contrast, an 
OOP approach means that, when a new possibility arises (that Rigellian 
land-squid is discovered), you can write a new class for that case, 
which knows how Rigellian land-squids kick, and *none* of the code that 
handles a person or a horse needs to change at all.  Jane probably 
doesn't care whether she's being kicked by a horse or by a land-squid, 
it's going to hurt either way!

Jeff Shannon
Technician/Programmer
Credit International






More information about the Tutor mailing list