(newbie) Is there a way to prevent "name redundancy" in OOP ?
fuzzyman at gmail.com
Fri Jan 5 21:52:58 CET 2007
Stef Mientki wrote:
> Not sure I wrote the subject line correct,
> but the examples might explain if not clear
> *** first attempt ***
> class pin:
> def __init__ (self):
> self.Name = 'Unknown Pin'
> aap = pin() # create an instance
> aap.Name = 'aap' # set it's name
> print aap.Name # print it's name
> # but why should I set it's name ??
> print 'aap' # I can just as well print a constant string !!
> # (ok there will be an extra check)
> *** second attempt ***
> class pin2:
> def __init__ (self, naam):
> self.Name = naam
> aap2 = pin2('aap2') # seems completely redundant to me.
> print aap2.Name
> print 'aap2'
> Can this be achieved without redundancy ?
Uhm.. if your code can work with a constant then creating an object to
hold it as an attribute is redundant.
If on the other hand you want an object to hold several attributes, and
methods for working with them, and then want to pass these objects
around your code with a single reference - then maybe an object is the
If you don't need custom classes then don't use them...
> Stef Mientki
More information about the Python-list