Тёмный

Refactoring C# with Chain of Responsibility 

Gui Ferreira
Подписаться 11 тыс.
Просмотров 7 тыс.
50% 1

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 RU-vid 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

Наука

Опубликовано:

 

6 мар 2023

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 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
@starterdev
@starterdev Год назад
Show us all the design patterns 🥰
@gui.ferreira
@gui.ferreira Год назад
There's a new one comming soon. 😉
@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.
@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 😉
@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 ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-yyKrt7zSmv0.html
@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.
@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 ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-yyKrt7zSmv0.html
@patbeansoo
@patbeansoo Год назад
Good stuff. Subscribed :)
@gui.ferreira
@gui.ferreira Год назад
Thanks, Vince! Welcome aboard!
@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: ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-_kV7lPOLISw.html
@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
@vagnerwentz1189
@vagnerwentz1189 Год назад
What is this IDE? JetBrains?
@gui.ferreira
@gui.ferreira Год назад
JetBrains Rider 🤘
@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
@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
Patrón de diseño Chain of Responsibility en C#
11:45
Start Your TDD Journey with C# in 15 MINUTES
14:55
Просмотров 19 тыс.
Visitor - Design Patterns in 5 minutes
3:20
10 Tools EVERY Software Engineer Should Know
9:46
Просмотров 8 тыс.
Why all your classes should be sealed by default in C#
11:43
Chain of Responsibility to the Rescue!
9:15
Просмотров 10 тыс.
Factory Pattern in C#: Creating Objects with Ease
12:54