The strategy pattern is a widely used design pattern that help you write better Python code. I'll show you how to apply the strategy using a practical example written in Python. I'll cover both the classic object-oriented version of the pattern, and I'll also show you a functional version that's a bit shorter to write and works equally well. At the end of the video, there's a more advanced bit where you'll see how to add type hints for functions as parameters.
All parts in this series:
Part 1: Cohesion and coupling - • Cohesion and Coupling:...
Part 2: Dependency inversion - • Dependency Inversion: ...
Part 3: The strategy pattern - • The Strategy Pattern: ...
Part 4: The observer pattern - • Observer Pattern Tutor...
Part 5: Unit testing and code coverage - • 100% CODE COVERAGE - T...
Part 6: Template method and bridge - • Two UNDERRATED Design ...
Part 7: Exception handling - • Exception Handling Tip...
Part 7b: Monadic error handling - • Monadic Error Handling...
Part 8: Software architecture - • Why You Should Think A...
Part 9: SOLID principles - • Uncle Bob’s SOLID Prin...
Part 10: Object creation patterns - • QUESTIONABLE Object Cr...
💡Here's my FREE 7-step guide to help you consistently design great software: arjancodes.com/designguide.
Relevant books:
- Design Patterns: Elements of Reusable Object-Oriented Software by Erich Gamma, Richard Helm, Ralph Johnson, and John Vlissides: amzn.to/3jllgyH
- Principles of Package Design: Creating Reusable Software Components by Matthias Noback: amzn.to/2NETK3l
- Clean Code: A Handbook of Agile Software Craftsmanship by Robert Martin: amzn.to/3qVZgNs
- The original Design Principles and Design Patterns article by Robert Martin: fi.ort.edu.uy/innovaportal/fi...
🎓 Courses:
The Software Designer Mindset: www.arjancodes.com/mindset
The Software Designer Mindset Team Packages: www.arjancodes.com/sas
The Software Architect Mindset: Pre-register now! www.arjancodes.com/architect
Next Level Python: Become a Python Expert: www.arjancodes.com/next-level...
The 30-Day Design Challenge: www.arjancodes.com/30ddc
🛒 GEAR & RECOMMENDED BOOKS: kit.co/arjancodes.
You can find the code I worked on in this episode in my GitHub repository: github.com/arjancodes/betterp...
Chapters:
0:00 Intro
1:30 Code example
3:21 Main problem with the code
4:01 Switching to a strategy pattern
5:23 Creating concrete strategies
6:56 Updating the process_tickets method
10:09 Adding a new strategy
11:03 A functional version of the strategy
13:18 Adding a function type hint
14:49 Outro
If you enjoyed this content, give this video a like. If you want to watch more of my upcoming videos, consider subscribing to my channel!
DISCLAIMER - The links in this description might be affiliate links. If you purchase a product or service through one of those links, I may receive a small commission. There is no additional charge to you. Thanks for supporting my channel so I can continue to provide you with free content each week!
Негізгі бет The Strategy Pattern: Write BETTER PYTHON CODE Part 3
Пікірлер: 203