[Edu-sig] Design Pattern question
urnerk at qwest.net
Sun Oct 19 22:43:12 EDT 2003
> Your idea is rather more funky, but what else are class
> variables for?
> Simon Burton.
What's also funky is how a shared superclass with no constructor can hold
shared instance methods, as well as shared class variables.
>>> class Foo:
# no constructor
def method1(self, a):
self.a = a
>>> class Spam(Foo):
self.b = 10
>>> o = Spam()
You can even define an instance method outside any class...
>>> def method2(self, c):
self.c = c
... then inject it into the superclass...
>>> Foo.method2 = method2
and all the children now have it.
I guess I'm just re-appreciating how flexible Python is. Design patterns
that just wouldn't be possible in other languages might have some currency
in Python world.
More information about the Edu-sig