Chain of Responsibility Pattern - DESIGN PATTERNS (C#/.NET)
Vložit
- čas přidán 14. 06. 2024
- Learn about the chain of responsibility pattern, which is a behavioral design pattern where the client passes a request through a chain of handlers. This pattern is helpful for decoupling the client from the specifics of how a request is handled.
Design patterns are important for implementing object-oriented designs and adhering to SOLID principles. Understanding these fundamental patterns helps software developers build clean and maintainable applications.
🕗 Timestamps:
0:00 - Pattern Introduction
1:50 - Demo Introduction
4:09 - Drawbacks without Chain of Responsibility Pattern
5:01 - Creating and Chaining Handlers
10:50 - Adding a Root Handler
14:23 - Extending the Root Handler
17:38 - Summary
📦 Source code: github.com/SingletonSean/desi...
🔁 Full playlist: • Design Patterns
💎 Become a Member: / @singletonsean
🏠 Discord: / discord
🐤 Twitter: / singletonsean_
🏆 Donate: www.paypal.com/donate?hosted_...
✉️ Email: youtube@singletonsean.com - Věda a technologie
Thanks
That's a good one, but can you please do with the DI? Because, currently you are passing the next handler directly but what if I have 3 or 4 handlers? Like H1 - H2 - H3 - H4. How should I manage this with DI? Also, what if each handler takes different types of arguments? The best example is a restaurant menu.
Good questions! I think even with DI, you'd have to manually resolve and pass in each handler, especially since they all implement the same interface.
Also, I would usually use this pattern if all the handlers take the same arguments. This makes the chain flexible, where we can re-order the different handlers without worrying about type issues.
Thanx. Can we use the Factory method?