[Tutor] OOP

Paul Sidorsky paulsid@shaw.ca
Thu, 21 Mar 2002 00:01:34 -0700


Cameron Stoner wrote:

You're more-or-less correct, just some minor points to clarify.  And
note that I'm not an OO person so if I've got something wrong then
somebody please correct me so I can learn too.

> - when making an instance(object) of a class it has all the
> behavior(functions or methods) of that class.

Yes, and also its own copy of all the properties (variables) of the
class.

> - objects take on all the characteristics of that class

True, and in Python they may also take additional characteristics or
properties strictly for that instance.  To use your example, if Max may
is a very special talking cat you can give him (and only him) a talk()
method and/or a voicetype property.  (In languages like C++ you can't
really do this without creating a derived TalkingCat class ahead of
time.)

>     The class cat has Max as an object that can play.

This is probably the only incorrect statement, at least technically. 
While it can be convenient to think of Max as "belonging to" the cat
class, in general the cat class has no way to know what objects you
create with it.  It's like a drawing template:  You take it off the
shelf, use it to draw a picture, and put the template back on the
shelf.  You can't look at the same template later to tell you stuff like
"I used this template to draw a triangle on a post-it note, a piece of
construction paper, and a cocktail napkin".  If you want to know this
you have to specifically make a record of it and for simplicity that
record is often external to both the class and all its objects.  (There
are ways to internalize such a record, though.)

> - you have to initiate play from Max

If and when you want Max to play, yes.  If you want other cats to play
you'd of course initiate it from them.  Also so-called "class variables"
and "class methods" can be initiated through their class without
necessarily having any instances. 

All in all though I'd say that was a pretty good summarization!

-- 
======================================================================
Paul Sidorsky                                          Calgary, Canada
paulsid@shaw.ca                        http://members.shaw.ca/paulsid/