Why a class when there will only be one instance?

SeeBelow at SeeBelow.Nut SeeBelow at SeeBelow.Nut
Wed May 26 00:42:43 EDT 2004


Roy Smith wrote:
> 
> In article <40B3F448.EB711333 at shaw.ca>, SeeBelow at SeeBelow.Nut wrote:
> 
> > > More than that, most times I've decided to not bother making something a
> > > class because it was too simple, I've eventually added enough
> > > functionality to it to change my mind and have to re-do things.  That's
> > > real cost.  Much simplier and cheaper to just make it a class from the
> > > get-go.
> >
> > Why does greater functionality make a class desireable, if there won't
> > be multiple instances created?
> 
> For me, it's more about encapsulation than code re-use.  If I've got a
> bunch of functions which operate on a collection of data, to me that
> says "object", which in Python (and most OOPL's) implies "class".

OK, that makes some sense - to associate certain data and code items and
separate them from other code and data.  Wouldn't that purpose be served
even better by putting them into a different file, and not bother with a
class?
 
> Bundling it up into a class lets me think about it as a unit.  Each
> class is a convenient thought unit for design and testing, and also for
> understanding somebody else's code.
> 
> I don't think there's a need to be dogmatic about it.  It's just what I
> find is a natural way to break a program down into smaller pieces you
> can get your brain around one piece at a time.


-- 
"Many are stubborn in pursuit of the path they have chosen, few in
pursuit of the goal." - Friedrich Nietzsche

http://annevolve.sourceforge.net is what I'm into nowadays.
Humans may write to me at this address: zenguy at shaw dot ca



More information about the Python-list mailing list