Re: Refactoring similar subclasses

2010-09-13 Thread Bruno Desthuilliers
Steven D'Aprano a écrit : I have some code that currently takes four different classes, A, B, C and D, and subclasses each of them in the same way: class MyA(A): def method(self, x): result = super(MyA, self).method(x) if result == "spam": return "spam spam spam"

Re: Refactoring similar subclasses

2010-09-11 Thread Steven D'Aprano
On Sat, 11 Sep 2010 08:53:38 +0200, Peter Otten wrote: > Steven D'Aprano wrote: > >> I have some code that currently takes four different classes, A, B, C >> and D, and subclasses each of them in the same way: [...] >> Any suggestions or guidelines? > > You could use a mixin: Nice! I'll give it

Re: Refactoring similar subclasses

2010-09-11 Thread Peter Otten
Steven D'Aprano wrote: > I have some code that currently takes four different classes, A, B, C and > D, and subclasses each of them in the same way: > > class MyA(A): > def method(self, x): > result = super(MyA, self).method(x) > if result == "spam": > return "spam

Refactoring similar subclasses

2010-09-10 Thread Steven D'Aprano
I have some code that currently takes four different classes, A, B, C and D, and subclasses each of them in the same way: class MyA(A): def method(self, x): result = super(MyA, self).method(x) if result == "spam": return "spam spam spam" return result #