Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #43053

How to subclass a family

Date 2013-04-08 11:44 +0200
From Antoon Pardon <antoon.pardon@rece.vub.ac.be>
Subject How to subclass a family
Newsgroups comp.lang.python
Message-ID <mailman.278.1365414362.3114.python-list@python.org> (permalink)

Show all headers | View raw


Here is the idea. I have a number of classes with the same interface.
Something like the following:

class Foo1:
    def bar(self, ...):
        work
    def boo(self, ...):
        do something
        self.bar(...)

What I want is the equivallent of:

class Far1(Foo1):
    def boo(self, ...)
        do something different
        if whatever:
            self.bar(...)
        else:
            Foo1.boo(self, ...)

Now of course I could subclass every class from the original family
from Foo1 to Foon but that would mean a lot of duplicated code. Is
there a way to reduce the use of duplicated code in such circumstances?

-- 
Antoon Pardon

Back to comp.lang.python | Previous | NextNext in thread | Find similar | Unroll thread


Thread

How to subclass a family Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2013-04-08 11:44 +0200
  Re: How to subclass a family Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-04-09 02:52 +0000

csiph-web