The Strategy Pattern Will Make Your Python Code CLEANER

Опубликовано: 02 April 2023
на канале: Isaac Harris-Holt
10,525
286

If we have lots of different ways of doing the same thing, how do we best represent that in Python? If we want to take a payment, but want to change our payment processor on the fly, how do we write clean, idiomatic Python code without lots of conditional statements everywhere?

Introducing the strategy pattern!

Check out the code:
https://github.com/isaacharrisholt/yo...

Resources:
Strategy pattern: https://en.wikipedia.org/wiki/Strateg...
Python Protocol PEP: https://peps.python.org/pep-0544/
Go interfaces: https://go.dev/tour/methods/9

__________________________________________

Check out my other socials!
🐦 Twitter ▶   / isaacharrisholt  
🖥️ Portfolio ▶ https://ihh.dev
📝 Blog ▶ https://isaacharrisholt.com
__________________________________________

Timestamps:
00:00 - Introduction
00:53 - What is the Strategy Pattern?
01:17 - Current code
02:20 - Refactor
03:42 - Adding a third data store
03:58 - But why bother?
04:26 - ABC comparison
05:03 - Single-method interfaces
06:22 - Outro

#python #softwareengineer


На этой странице сайта вы можете посмотреть видео онлайн The Strategy Pattern Will Make Your Python Code CLEANER длительностью часов минут секунд в хорошем качестве, которое загрузил пользователь Isaac Harris-Holt 02 April 2023, поделитесь ссылкой с друзьями и знакомыми, на youtube это видео уже посмотрели 10,525 раз и оно понравилось 286 зрителям. Приятного просмотра!