The Strategy Pattern Will Make Your Python Code CLEANER

preview_player
Показать описание
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:

Resources:

__________________________________________

Check out my other socials!
__________________________________________

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
Рекомендации по теме
Комментарии
Автор

I was nodding along thinking 'ok this is cool but i'll just stick to abc' until i got to 5:35 🤯 really nice video

staystealth
Автор

Just stumbled across your channel and found this video very informative, subbed 😊

rnzqt
Автор

First time I've heard "strategy pattern". However, I have implemented something like this many times.

Dependency Injection?
Composable Interfaces?
Traits?
Heck, even a C header declaration can do this.

codeman-dev
Автор

You can use the @property decorator on methods in protocols to make it mean a normal property

knut-olaihelgesen