(newbie) Is there a way to prevent "name redundancy" in OOP ?

Stef Mientki S.Mientki-nospam at mailbox.kun.nl
Fri Jan 5 20:09:47 CET 2007


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 ?

thanks,
Stef Mientki



More information about the Python-list mailing list