Refactoring C# with Chain of Responsibility

  Рет қаралды 6,846

Gui Ferreira

Gui Ferreira

Жыл бұрын

What is the Chain of Responsibility Design Pattern, and how can I apply it in C#.
💎 Be a Patreon to get the source code: / gsferreira
🚨 KEY LINKS
🤝 Support me on Patreon (and get access to source code) here: / gsferreira
👋 HEY FRIEND
If you're new to my Channel, my name is Guilherme, but you can call me Gui if Portuguese pronunciation is not your thing.
I see myself as a Minimalist Software Craftsman. That says a lot of what I talk about here.
So, why this KZbin channel? To share with you to simplify your life as a Developer through knowledge, technology, and practices.
If you are into those things as I do, don't forget to subscribe for new videos.
🔗 GET IN TOUCH
LinkedIn: / gferreira
Twitter: / gsferreira
GitHub: github.com/gsferreira
Visit my blog: gsferreira.com
#dotnet #csharp

Пікірлер: 48
@OrgesKreka
@OrgesKreka Жыл бұрын
Please do another video on design patterns!
@gui.ferreira
@gui.ferreira Жыл бұрын
Any Design Pattern, in particular, you would like to see?
@kostasgkoutis8534
@kostasgkoutis8534 Жыл бұрын
I would like to see a video on Pipes and Filters pattern and on State Machines. Together with the Chain of Responsibility, Mediator, and Rule Engine patterns, they form (for me) a logical "pipeline patterns" group (maybe with the Monad pattern as well).
@gui.ferreira
@gui.ferreira Жыл бұрын
That's a big list 😁 Thanks for sharing
@ahmet9424
@ahmet9424 Жыл бұрын
Great sample app 👍 Thank you.
@gui.ferreira
@gui.ferreira Жыл бұрын
Glad you like it! Thanks!
@moab5102
@moab5102 Жыл бұрын
Thank you that's an excellent video I would like a tutorial about rule engine or specification design pattern keep up the good work
@gui.ferreira
@gui.ferreira Жыл бұрын
Thanks for the suggestion. Added to the content idea list 😉
@nucasspro1
@nucasspro1 Жыл бұрын
Thank you so much, after watching this video, now I realize asp net core pipeline is following this pattern
@gui.ferreira
@gui.ferreira Жыл бұрын
Excellent and accurate observation! I'm happy you find this video useful.
@starterdev
@starterdev Жыл бұрын
Show us all the design patterns 🥰
@gui.ferreira
@gui.ferreira Жыл бұрын
There's a new one comming soon. 😉
@alexandrgoncharov5074
@alexandrgoncharov5074 Жыл бұрын
thank you for the video. great explanation
@gui.ferreira
@gui.ferreira Жыл бұрын
Glad you liked it 🙏 Thanks for taking the time to write feedback.
@patbeansoo
@patbeansoo Жыл бұрын
Good stuff. Subscribed :)
@gui.ferreira
@gui.ferreira Жыл бұрын
Thanks, Vince! Welcome aboard!
@sunnypatel1045
@sunnypatel1045 Жыл бұрын
I be keep to see your experience with observer and visitor design patterns
@gui.ferreira
@gui.ferreira Жыл бұрын
I'm likely doing one on Visitor soon.
@gui.ferreira
@gui.ferreira Жыл бұрын
Here it is the video on the Visitor Design Pattern kzbin.info/www/bejne/r6quo6dtr7igrJI
@FreeMindInMotion
@FreeMindInMotion Жыл бұрын
Great explanation. Visitor pattern would be interesting
@gui.ferreira
@gui.ferreira Жыл бұрын
Noted 😉 Anything, in particular, you would like to see on the Visitor Pattern?
@FreeMindInMotion
@FreeMindInMotion Жыл бұрын
For me the visitor use case is difficult to identify. That's why I chose it 😀 Maybe you have a good example pointing out the double polymorphic dispatch.
@FreeMindInMotion
@FreeMindInMotion Жыл бұрын
Taking your example with the order I think it could be used, if you have IOrder, PriorityOrder and NormalOrder. Both need to be handled by the different Handlers, but differently by each or at least some handlers based on their concrete type without type checking.
@gui.ferreira
@gui.ferreira Жыл бұрын
@@FreeMindInMotion Let me think about it 😁
@gui.ferreira
@gui.ferreira Жыл бұрын
Here it is the video on the Visitor Design Pattern kzbin.info/www/bejne/r6quo6dtr7igrJI
@saqibali7066
@saqibali7066 Жыл бұрын
Good example, Please do explain strategy design pattarn.
@gui.ferreira
@gui.ferreira Жыл бұрын
Added to the pipeline! Anything, in particular, you would like to see on Strategy Pattern?
@saqibali7066
@saqibali7066 Жыл бұрын
@@gui.ferreira how the flow goes ? Is loading web project configuration dynamically is good example mean either I can read configuration from web.config or from dynamoDB
@gui.ferreira
@gui.ferreira Жыл бұрын
@@saqibali7066 I published it weeks ago: kzbin.info/www/bejne/lZy5aJ-GhLF8idk
@saqibali7066
@saqibali7066 Жыл бұрын
@@gui.ferreirathanks
@ghevisartor6242
@ghevisartor6242 8 ай бұрын
I wonder if this is correct to use in a case where i don't have a commonality like a "discount approval" but regardless i need to check a bunch of conditions, for example for deleting a file. Basically to get those conditions, in one i have to check the database, in another just some of the file properties. By separating these into their own handler, now i have the DbContext for example just in the first handler and not the other. So i end up with "IsFileInUseHandler", "IsFileOlderThanHandler" and then lastly "DeleteFileHandler" where i do File.Delete(filePath). It seems to work fine and simplify the code, but as you can see from the naming it sounds odd, also the last handler is actually having side effects. Am i trying to force a square in a circle?
@gui.ferreira
@gui.ferreira 8 ай бұрын
You are building a pipeline, which is a common practice here. As an example, I've seen many implementations similar to the one you mention in MediatR pipelines (which is a Chain of Responsibility).
@LucasSantos-yw4nh
@LucasSantos-yw4nh Жыл бұрын
Do you see any performance downgrade between Chain Of resposibility and Strategy Pattern? Also, is there any technique to find the the best order to fit the handlers in the chain?
@gui.ferreira
@gui.ferreira Жыл бұрын
To be honest, they solve different problems, so it's not fair to compare them. Regarding the order, it depends on the problem they are solving. In the example from the video, order matters. But, in some cases, the Order can be ignored. For example, if you want to apply Authorization restrictions, you may want to start with the least resource-intensive ones. Long story short, it depends on the domain and business context. Did my answer help? 😅
@LucasSantos-yw4nh
@LucasSantos-yw4nh Жыл бұрын
@@gui.ferreira Yeah, it helped, thanks. But I still think both design patterns solve the open closed principle in order to create new behaviors without the need to change the class. I would like to know more about your point that it solves different problems.
@gui.ferreira
@gui.ferreira Жыл бұрын
@@LucasSantos-yw4nh When I say that they solve different problems it's because Strategy is about having a generic interface that you can use to provide different implementations. On the other hand, a Chain of responsibility is about having a chain of objects which usually go from more detailed to more generic. So, you may solve the same problem with both, but not all the problems.
@xmadcode
@xmadcode Жыл бұрын
The Chain Of Responsibility and the Pipeline Patterns would make a fair comparison, not as with the Strategy Pattern, in my opinion
@xmadcode
@xmadcode Жыл бұрын
The strategy pattern
@gui.ferreira
@gui.ferreira Жыл бұрын
Added to the list! 😉 Anything you would like to see on Strategy Pattern?
@xmadcode
@xmadcode Жыл бұрын
@@gui.ferreira an overview of the pattern with a simple real life implementation in C#, and how can someone spot a use case for the pattern, would a make a great video ;)
@gui.ferreira
@gui.ferreira Жыл бұрын
@@xmadcode Thanks for the Tip. I will think about it!
@SimonLomax-qw3dv
@SimonLomax-qw3dv Жыл бұрын
What colour theme are you using?
@gui.ferreira
@gui.ferreira Жыл бұрын
Hi! Dracula for Rider plugins.jetbrains.com/plugin/12275-dracula-theme
@vagnerwentz1189
@vagnerwentz1189 Жыл бұрын
What is this IDE? JetBrains?
@gui.ferreira
@gui.ferreira Жыл бұрын
JetBrains Rider 🤘
@SteveNgaiCheeWeng
@SteveNgaiCheeWeng Жыл бұрын
can we also refactor it with DDD?
@gui.ferreira
@gui.ferreira Жыл бұрын
Not sure what you are thinking about. For sure, the service/application can be modeled using DDD. However, Design Patterns like the Chain of Responsibility are useful even with DDD. Can you detail your question?
FINALLY, the Visitor Design Pattern makes Sense
11:03
Gui Ferreira
Рет қаралды 7 М.
Favor Method Chaining Over Nested Calls | Clean Code
10:23
Zoran Horvat
Рет қаралды 24 М.
DEFINITELY NOT HAPPENING ON MY WATCH! 😒
00:12
Laro Benz
Рет қаралды 49 МЛН
Я нашел кто меня пранкует!
00:51
Аришнев
Рет қаралды 4,7 МЛН
Why all your classes should be sealed by default in C#
11:43
Nick Chapsas
Рет қаралды 91 М.
Chain of Responsibility Pattern - DESIGN PATTERNS (C#/.NET)
19:16
SingletonSean
Рет қаралды 1,7 М.
Visitor - Design Patterns in 5 minutes
3:20
levonog
Рет қаралды 770
Start Your TDD Journey with C# in 15 MINUTES
14:55
Gui Ferreira
Рет қаралды 19 М.
10 Tools EVERY Software Engineer Should Know
9:46
Gui Ferreira
Рет қаралды 8 М.
Chain of Responsibility Design Pattern in detail | Interview Question
9:49
Chain of Responsibility to the Rescue!
9:15
Zoran Horvat
Рет қаралды 10 М.
Don't throw exceptions in C#. Do this instead
18:13
Nick Chapsas
Рет қаралды 253 М.
The Missing TDD Skill according to Kent Beck
9:51
Gui Ferreira
Рет қаралды 1,6 М.
How do I Stay Organized as a Developer
15:21
Gui Ferreira
Рет қаралды 2 М.
$1 vs $100,000 Slow Motion Camera!
0:44
Hafu Go
Рет қаралды 22 МЛН
Здесь упор в процессор
18:02
Рома, Просто Рома
Рет қаралды 339 М.
Хотела заскамить на Айфон!😱📱(@gertieinar)
0:21
Взрывная История
Рет қаралды 6 МЛН
تجربة أغرب توصيلة شحن ضد القطع تماما
0:56
صدام العزي
Рет қаралды 53 МЛН