Design Patterns: Strategy
ฝัง
- เผยแพร่เมื่อ 22 ก.ย. 2024
- This is the second of an eight part series where Robert is joined by Phil Japikse to discuss design patterns. A design pattern is a best practice you can use in your code to solve a common problem. In this episode, Phil demonstrates the Strategy pattern. This pattern enables an algorithm's behavior to be selected at runtime.
Resources:
- Sample code: github.com/ski...
- Design Patterns: Elements of Reusable Object-Oriented Software book: www.amazon.com...
- Head First Design Patterns book: www.amazon.com...
Full list for this series:
0. SOLID Design Patterns (start from here): th-cam.com/video/agkWYPUcLpg/w-d-xo.html
1. Design Patterns: Command/Memento: th-cam.com/video/zRbHlDeon3E/w-d-xo.html
2. Design Patterns: Strategy: th-cam.com/video/QZIvlny1Onk/w-d-xo.html
3. Design Patterns: Template Method: th-cam.com/video/MfAvs0n9uMs/w-d-xo.html
4. Design Patterns: Observer and Publish-Subscribe: th-cam.com/video/72bdaDl4KLM/w-d-xo.html
5. Design Patterns: Singleton: th-cam.com/video/sbML3xFHRbI/w-d-xo.html
6. Design Patterns: Factories: th-cam.com/video/JEk7B_GUErc/w-d-xo.html
7. Design Patterns: Adapter and Façade: th-cam.com/video/XYa0rmRMZ1Q/w-d-xo.html
8. Design Patterns: Decorator: th-cam.com/video/6PPMR0GWrZQ/w-d-xo.html
such a great series. rewatching all of them before software architecture exam later this week
I love the videos but I don't know why there is not a playlist for design patterns as I want a sequence to learn all the design patterns. Overall it helps a lot.
th-cam.com/video/QZIvlny1Onk/w-d-xo.html&ab_channel=MicrosoftVisualStudio
I thought the description of "changing behavior at runtime" was confusing because it just sounds like just regular conditional logic, like an if/else or switch. But the superhero example clarified it and especially the "do your thing" phrase. I would recommend just highlighting that the different strategies are being defined in a different place than they are being executed, whereas in simple conditional logic those are together.
I think that is what 11:45 is about. The demo code doesn't really capture it, but they do talk about that fact several times. I agree it would be cool to have flashing letters to really drive the point home haha.
I appreciate you guys so much for you work! It's good quality, yet simple! Good job!
This is great. Thanks for sharing
How many accounts do you have? Or you trading from a single one? tell us pls
I have a doubt.
We can achieve the same like below.
IHero spiderMan = new SpiderMan();
Assert.Equal(new WeaveWeb().ExercisePower(),spiderMan.DoHeroStuff());
spiderMan = new SuperMan();
Assert.Equal(new WeaveWeb().ExercisePower(),superMan.DoHeroStuff());
spiderMan = new BatMan();
Assert.Equal(new WeaveWeb().ExercisePower(),BatMan.DoHeroStuff());
Then why do we need Strategy pattern. Please guide.
Because you want spiderMan (the initial object) to DoHeroStuff, and not a SuperMan. In other words, assigning SuperMan to spiderMan changes the original context that you want to operate on.
Thanks so much!
Guys that was hilarious! :) Loved it. Keep the good work!
Can you provide the link of before video of this series?
It very helpful if you can make video on dispatcher pattern
I think a stateless example would be better.
I have seen lot of playlists on TH-cam for design patterns. This is by far the least useful for developers. it is good if you are real amateur and and want the intro paragraph as a dialogue. Chapter 1 is never coming. Too much philosophical talk.