Strategy Pattern, The Best Software Design Pattern

preview_player
Показать описание
The strategy pattern is my favorite software design pattern

👨‍👨‍👦‍👦 Social
▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬
Рекомендации по теме
Комментарии
Автор

I didn't know this was called the strategy pattern, to me its just an example of why and how interfaces are useful lol

nanonkay
Автор

It's all about interchangeability. Also, those are pretty cool animations it helps to get a better grasp on the examples

eliseusalomao
Автор

But couldn't I have just extracted the switch statement logic into individual methods?

Clean code fans vs monolith class enjoyers

But seriously lately I have been bothered about how convoluted it becomes to trace code after adopting proper architecture patterns. Maintainability is easier in some ways but also harder in other ways 😓

TESkyrimizer
Автор

it added an abstraction layer, everything is happening within that method containing the switch statement, it's just fine cuz the service where the business logic happens does not need to worry about the instanciation of the OrderNotifier type

francksgenlecroyant
Автор

Would have liked to see an runtime implemention / usage of this examples, because the example u gave was using the Startup of the app to choose one of the implementations, but most times I feel like u would use this in runtime with some kind of Resolver to get the wanted implementation of the Interface.

Still very well explained, my favorite pattern as well

ricardoduarte
Автор

I see a switch still! It's just in the DI.

You can't always do this if you need to decide based on the

seannewell
Автор

The interpreter pattern is such a good pattern you can implement every pattern, including itself, in it

SimGunther
Автор

Brother, Please cover all design patterns in these short videos please. It is just the world's best video to revise a pattern or to get a quick intro if you are new to them.

DrFlash-mhst
Автор

It is also great for finding different calculation strategies

guidosalescalvano
Автор

Nice one. A strategy factory would be nice then you just have a new registration for each type and you're done. OCP FTW.

fifty-plus
Автор

This is the same thing as the delegate pattern although you could make an argument that delegates have more methods and/or are long lived but still the same imo. Either way this becomes extremely powerful when using mock strategies/delegates for testing.

TuscaniGT
Автор

It's my favorite pattern, but usually I has to be combined with another logic and/or pattern to be the most useful.

For example I used it in a validator class.
There I created an interface for validation rules. They have one "isApplicable" method that accepts the validation rules of the current request and return a boolean, and a "validate" method, that return a validation response with an optional error message bag.
The validator has a method for registering validation rules.
Whenever it receives a request, it will then loop through all registered validation rules, validate the request for each one that is applicable for it and collect all error messages.
Adding new validation rules is very easy and you don't have to touch any existing code apart from the place where the rules are registered.
Not a single "switch" used anywhere :)

Fanmadeb
Автор

What do you do if a customer wants to receive both email and SMS notifications? What is the best way to deal with that?

srki
Автор

What if we must send the notification through all the providers (including the pigeon 😁) ?

PankajNikam
Автор

The pattern itself is fine, but the example has a problem in my opinion.

An “EmailService” or an “SMSService” should have limited responsibility. The “EmailService” shouldn’t know how to send an order confirmation. This can be the responsibility of a class that implements the interface and uses the “EmailService”. By using composition, your “EmailService” will stay simple and be more portable between implementations.

zyph.
Автор

excellent explanation Jono. Short and as we said in colomba "Al grano"

alexulag
Автор

My professor introduced this pattern, but had written several Java files to implement it with complex relationships.

I implemented it functionally in 7 lines of code.

This is one reason why I really really hate OOP related crap.

Nellak
Автор

This is surprisingly common thing to do. I didn't know it was called Strategy. Isn't this what interfaces are about?

avinashsuresh
Автор

Hello! What do you use to create these stunning code presentation videos

pacholoamit
Автор

good video plz make more content like this.

nengforgame
visit shbcf.ru