Python Design Patterns
summary
Covers concrete Python patterns and tradeoffs with runnable examples: replaces hardwired time.sleep by inject time.sleep so a scheduler uses a fake clock for fast deterministic tests, shows how singleton breaks with subclassing and why shared-state singletons fail, contrasts factories vs dependency injection for unpredictable object counts, demonstrates safe use of monkeypatch for emergency and prefers explicit injection, explains callbacks/Hollywood, lazy imports, decorators and observers with practical caveats and when each approach actually simplifies testing and extension.
AI-written summary · about
chapters (27)
- 0:00Intro
- 2:05A Pattern Example
- 3:19Solution: the Facade DP
- 5:32Facade is a Design Pattern
- 10:13Some Facade KUS
- 12:34Is Facade a "Pythonic" DP?
- 15:43Design Patterns
- 16:02Step back: what's a Pattern?
- 17:15A Pattern's problem(s)
- 18:05A Pattern's "solution(s)"
- 19:35Why bother w/Patterns?
- 22:34"Design" is a vague term...
- 23:20What's a "Pythonic" Pattern
- 27:54Python: hold or wrap?
- 31:58Creational Patterns
- 33:50Singleton ("Highlander")
- 35:56Monostate ("Borg")
- 37:24Creational DPs: "Flexibility"
- 41:34DI: why we want it
- 45:32Template Method vs DI
- 47:50TM-VS-DI issues
- 49:21Monkey-patching
- 51:30Dependency Injection
- 53:50DI design-choice details
- 56:10DI and factories
- 58:23The Callback Pattern
- 59:10The "Callback" concept
related talks
46mOn Being Pythonic
36mPractical Python Design Patterns
24mPython for Humans, Designing Python Code Like a User Interface
30mWrite faster Python! Common performance anti patterns
33mElegant Solutions For Everyday Python Problems
32mPractical usage of advanced Python constructs
27mFunctional Programming for Pythonistas
19mPython - best practices
