Description
Lets you separate algorithms from the objects on which they operate.
Where to use
- Compilers (AST traversal). \n
- Exporting data.
Real World Example
You have a graph of shapes. You write an 'XMLExportVisitor' that walks the graph and generates XML, without modifying the shape classes.
Code Example
class Visitor:
def __init__(self):
pass
def execute(self):
print('Executing Visitor')
