Delegation in Python

Brian Gladman noone at nowhere.net
Sun Jan 25 00:58:39 CET 2015


On 24/01/2015 23:47, Gary Herron wrote:
> On 01/24/2015 03:38 PM, Brian Gladman wrote:
>> On 24/01/2015 23:22, Chris Angelico wrote:
>>> class RF(Fraction):
>>>      def is_integer(self):
>>>         return self.numerator % self.denominator == 0
>> Thanks for your help on this.  I must admit that nowhere in a lot of
>> searching did I find that delegation is achieved by doing nothing!
>>
>>     Brian
> 
> That's *not* "doing nothing".   And it's not even really "delegation". 
> It's just sub-classing Fraction to add one new method and inherit all
> other methods.

I realised that - I was being whimsical.

I really did want true delgation so that I get an RF returned even when
I delegate to Fractions.

   Brian




More information about the Python-list mailing list