The Visitor Design Pattern and Python
Epiphany.
In Python, with iterators, the Visitor design pattern is useless. And a strongly-ingrained habit. Which I'm trying to break.
Here's a common Visitor approach:
class Visitor: def __init__( self ): ... def visit( self, some_target_thing ): ... def all_done( self ): ... v = Visitor() for thing in some_iterator(): v.visit(thing) v.all_done()
If we …
more ...