[Tutor] when to use OOP

Sean 'Shaleh' Perry shalehperry@attbi.com
Fri, 09 Aug 2002 23:49:26 -0700 (PDT)


On 10-Aug-2002 Frank Holmes wrote:
>    After beating my head against classes for a while, I think I am finally 
> beginning to understand how to write them (well, simple ones at least). So 
> now the next question arises... when/why would I use class rather than a 
> straightforeward script with just alotta def() statements?
> 

the whole point of OOP is to think in terms of objects, i.e. real things.  This
means nouns which have state/data and verbs which cause them to perform actions.

GUI programming is one place where OO is rather handy and obvious.  Having a
Window class which draws itself makes sense.  A list of windows which your
program owns is then quite simple.

When I find myself defining data and then writing functions to act on the data
I usually ask myself if a class is not what is really needed.

When I find myself wanting multiple instances of a particular state I usually
turn to a class.  For instance a networking daemon which handles multiple
simultaneous connections might have a class for each connection.