[Tutor] OOP purpose

Kirby Urner urnerk@qwest.net
Tue, 02 Apr 2002 11:51:56 -0800


At 12:16 PM 4/2/2002 -0600, you wrote:
>Hi all,
>
>What is the purpose of OOP?  Why  would you use it instead of
>just modular design?  I am having trouble finding the need
>to use it in my projects.
>
>Thanks,
>
>Cameron Stoner

I have this module called povray.py that outputs text in a
form suitable for rendering by Povray, a ray tracer.  The
core functionality is written as a class definition.

Now, if I have a specialized need to do something fancier
with Povray than my original class allows, I can just
subclass it.  This is good because sometimes the additional
functionality is very specialized (like I'm making the
cylinders and spheres look a certain way for a client,
maybe plastic and metalic respectively, plus I'm adding
cones), and because another project will require a
different kind of enchancement -- so I create a sibling
descendent, another subclass.

Were I not using the class/inheritance approach, my
inclination would be either to (a) continue complicating
the povray module with all kinds of bells and whistles,
mixing together features from multiple projects or (b)
always cutting and pasting a new copy of the original
module, and then expanding it in various ways.  Neither
(a) nor (b) would be as convenient.  With inheritance,
if I think of a way to enhance core functionality, I do
it once in the super class, and all subclasses benefit.
If I'd cloned the original code, I'd have to update each
clone.  And (a) would just make my code too complicated
and therefore difficult to maintain.

Kirby