Variable inheritance

Roman Suzi rnd at onego.ru
Tue May 22 06:37:37 EDT 2001


On Tue, 22 May 2001, Oleg Broytmann wrote:

> 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".

Nope. Telephone IS CommunicationDevice. And this is on direct 
inheritance path. 

So, there is nothing wrong. "Communicativeness" is the main 
property of the whole line. It's almost in the definition.
 
>    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.
> 
> 

Sincerely yours, Roman A.Suzi
-- 
 - Petrozavodsk - Karelia - Russia - mailto:rnd at onego.ru -
 





More information about the Python-list mailing list