how to dispatch objects depending on their class
Curzio Basso
curzio.basso at unibas.ch
Wed Aug 11 04:05:10 EDT 2004
cmedcoff at hotmail.com wrote:
> Visitor Pattern?
Actually, I thought what I was describing was a visitor pattern but I am
probably wrong.
Is it correct that in the visitor pattern the dispatching would be
delegated to the classes, like with:
class A(object):
def __init__(self):
pass
def accept(self, visitor)
visitor.do_something_with_A(self)
class B(A):
def __init__(self):
A.__init__(self)
def accept(self, visitor)
visitor.do_something_with_B(self)
class Visitor(object):
def __init__(self):
pass
def do_something_with_A(self, object):
pass
def do_something_with_B(self, object):
pass
Then I would call
a = A()
b = B()
v = Visitor()
a.accept(v)
b.accept(v)
Is this correct?
thanks, curzio
More information about the Python-list
mailing list