Variable inheritance

Oleg Broytmann phd at phd.fep.ru
Tue May 22 11:00:24 CEST 2001


On Tue, 22 May 2001, Roman Suzi wrote:
> >    But grey mouse DOES NOT "contains" grey color. The mouse IS really grey
> > thing, hence I used inheritance.
>
> It could be _said_ of everything:
>
> Thing IS HavingSomethingThing
>
> instead of
>
> Thing HAS Something
>
> ;-)
>
> (Note, that the later is much shorter and clearer!)

   Not always. Telephone IS CoomunicatingDevice, but why do want it to "HAS
communication abilities".

   And what is more important, when you declare

class Telephone(CommunicatingDevice): pass

   you can use methods from tha class CommunicatingDevice. When you declare

class Telephone:
   def __init__(self, device):
      self.comm_device = device

   you cannot. You must redeclare them yourself and delegate them:

class Telephone:
   def __init__(self, device):
      self.comm_device = device

   def method1(self):
      self.comm_device.method1()

   def method2(self):
      self.comm_device.methodo2()

   This is certainly neither shorter nor cleaner :-/

Oleg.
----
     Oleg Broytmann            http://phd.pp.ru/            phd at phd.pp.ru
           Programmers don't die, they just GOSUB without RETURN.





More information about the Python-list mailing list