← All videos

The Visitor Pattern in Python (And Better Alternatives)

ArjanCodes · 39.5K views · 12 days ago
Show description

💡 Learn how to design great software in 7 steps: arjan.codes/designguide. The Visitor pattern has a reputation for being complicated, but the problem it solves is actually quite simple: what happens when you keep adding new operations to the same set of objects? In this video, I use a document editor to compare several ways to solve that problem: methods, pattern matching, the classic Visitor pattern, a dispatch matrix, and Python’s `singledispatch`. More importantly, we’ll look at the trade-offs of each approach and when Visitor is actually worth using. 🔥 GitHub Repository: git.arjan.codes/2026/visitor. 💬 Join my Discord server: discord.arjan.codes. ⌨️ Keyboard I’m using: amzn.to/49YM97v. 🔖 Chapters: 0:00 Intro 1:23 Methods on the Nodes 2:41 Pattern Matching Groups Code by Operation 3:53 Classic Visitor 6:23 The Design Problem 7:06 The Dispatch Matrix Underneath Visitor 9:35 Let Python Maintain the Matrix 11:46 Final Thoughts #arjancodes #softwaredesign #python

Open on YouTube ↗