The State Pattern Done the Pythonic Way

Veröffentlicht am: 10 April 2026
auf dem Kanal: ArjanCodes
42,287
1.6k

🧱 Build software that lasts. Join the Software Design Mastery waiting list → https://arjan.codes/mastery.

The classic State design pattern is often implemented with many small classes and heavy inheritance. In this video, I show a different approach.

I start with the traditional object-oriented version and then refactor it into a generic, data-driven state machine using Python features like decorators, enums, and generics. The result is a clean, reusable engine where transitions are explicit and easy to understand.

🔥 GitHub Repository: https://git.arjan.codes/2026/state.

🎓 ArjanCodes Courses: https://www.arjancodes.com/courses.

💬 Join my Discord server: https://discord.arjan.codes.

⌨️ Keyboard I’m using: https://amzn.to/49YM97v.

🔖 Chapters:
0:00 Intro
3:24 Why This Matters
4:11 Step 1 — The Traditional Class-Based State Pattern
4:57 Step 2 — Realization: This Is Just a Lookup Table
5:21 Step 3 — Extracting a Generic StateMachine
17:35 Step 4 — Making Transitions Declarative with a Decorator
20:37 Step 5 — Supporting Multiple From States
24:05 The Payment Class Becomes Boring (In a Good Way)
25:30 When To Use This vs Classic OO
25:54 Final Thoughts

#arjancodes #softwaredesign #python


Auf dieser Seite können Sie das Online-Video The State Pattern Done the Pythonic Way mit der Dauer stunde minuten sekunde in guter Qualität ansehen, das der Benutzer ArjanCodes 10 April 2026 hochgeladen hat, den Link mit Freunden und Bekannten teilen, dieses Video wurde auf Youtube bereits 42,287 Mal angesehen und es wurde von 1.6 tausend den Zuschauern gefallen. Viel Spaß beim Betrachtenden Zuschauern gefallen!