python's OOP question
Kay Schluehr
kay.schluehr at gmx.net
Mon Oct 16 05:52:40 EDT 2006
neoedmund wrote:
> Could you show some code to help me know how composition/delegation can
> be done here? Thanks.
Starting with your example C2 might just derive from C1 and perform a
supercall:
class C1(object):
def v(self, o):
return "expected "+o
class C2(C1):
def v(self, o):
return "unexpected "+o
def m(self):
print super(C2,self).v("aaa")
>>> c2 = C2()
>>> c2.m()
expected aaa
But in general there is no single pattern to deal with object
composition.
More information about the Python-list
mailing list