One of the biggest problems developers face with learning designed patterns is finding practical use cases. I can't recall seeing a more practical use case for a design pattern than the one you just presented. Congratulations. This is great content.
Here you go, one more real world example: I use Chain of Responsibility to process email messages. Each link is responsible for a different processing element: extract data from body, tax number validation, finding the customer in db.
Simple explanations! Watched your Course on functional programming on pluralsight in 2019 or so, changed my life! Program in go these days but still these videos are so enjoyable and informative that cant pass on.
Really That is amazing explain , i have searched about videos explain Design patterns to understand it until i found and watch your videos really it were Awesome thank you too much.
I use chain of responsibility a lot! It is the easiest way to avoid making god objects that know everything. I did learn of the pattern before I knew how it was called when working with Spring Framework and Symfony, which often uses a variation where you first call supports() method that returns a boolean and if it return true you call the aggregate method. The only thing you can do wrong with this pattern is that one of the chains is relying on a state change in a previous chain as those dependencies are easy to miss. I prefer a chain to be functional and immutable.
Really interesting video - thanks for sharing. Also, a very good and practical example. I was following along, but used Java 17 for the implementation. To my surprise, I realised that Java already includes the Chain of Responsibility in its Comparator class, via the `.thenComparing()` method. Nice. 🙂
Now that you said it, I think I remember it does. Java has one practical feature that i like a lot - functional interfaces. So many interfaces only expose one method, and the ability to use lambdas and interfaces interchangeably is really useful.
Hi, Thank u for the interesting video. Should we mentioned that the same can be achieved using LINQ? If yes, should we consider LINQ chaining as the Chain of Responsibility?
If the nodes are organized into an IEnumerable, then LINQ is a viable option. Though, you must take care to construct a correct expression. In the example from the video, nodes are NOT ordered into a sequence.
Nice and practical video. However, in C# this can happen using linq. Is linq actually doing an implementation of "Chain of Responsibility" ? Or it the the Comparer itself that is "chained" and it be used both in List.Sort and IEnumerable.OrderBy() ?
It depends on what you mean by "doing an implementation". If you consider the example implementation from the GoF pattern, then it is only one possibility. It is far from being the only one, let alone the best implementation one can come up with. In my opinion, design patterns are not their implementations, but the externally visible interaction, usually - but not always - implemented via object injection. In the case of the Chain of Responsibility, there are two principal implementations that correspond to linked list vs. array list, with all pros and cons of both approaches. Using LINQ operators such as SkipWhile, First, etc. makes it no different than the CoR implementation from the GoF book, which is based on object chaining. So, the answer to your question does LINQ implement CoR is (in precise terms): no, it doesn't. But the caller could not tell the difference anyway, due to encapsulation.
@@zoran-horvat Thank you Zoran for you answer. It totally makes sense your "point of you" about what design patterns really are and teach us this way of thinking. I already bought your Udemy course on this topic and I look forward to studying it in detail. How would you do the the sorting of a collection in C# ? Would you use the linq support to "Chain' method calls like "OrderByDescending(comparer1).ThenBy(comparer2)..." *OR* "OrderBy(comparer1.Then(comparer2))" which is your example of CoR (let's imagine that we don't want to use List.Sort())? Is it a matter of preference or what ? And by the way, I am not aware what the example implementation from the GoF book is :)
@@MrJonnis13 The CoR implementation in GoF is literally a linked list of objects. I have used CoR several times in practice and I always flattened that into a list for performance gains (which were measurable). Regarding sorting, from what I have seen in the LINQ source code, OrderBy and ThenBy methods are heavily optimized and I see no reason to avoid them. My guess is that they could even perform better than the custom chained comparer. The reason for having the chained comparer is for the sake of sorting methods that can only accept one IComparer, such as the List's Sort method.
Become a patron and get access to source code and exclusive live streams: www.patreon.com/posts/chain-of-to-81381632
One of the biggest problems developers face with learning designed patterns is finding practical use cases. I can't recall seeing a more practical use case for a design pattern than the one you just presented. Congratulations. This is great content.
Here you go, one more real world example: I use Chain of Responsibility to process email messages. Each link is responsible for a different processing element: extract data from body, tax number validation, finding the customer in db.
Your pluralsight and udemy courses are fire! Thanks for all the great content!
Simple explanations! Watched your Course on functional programming on pluralsight in 2019 or so, changed my life! Program in go these days but still these videos are so enjoyable and informative that cant pass on.
He made another functional programming course on pluralsight. it's on my watch list.
Functional c# 10 - mine too :)
A very nice real-world example of the pattern in use.
Really That is amazing explain , i have searched about videos explain Design patterns to understand it until i found and watch your videos
really it were Awesome
thank you too much.
I like how practical your examples are!
I use chain of responsibility a lot! It is the easiest way to avoid making god objects that know everything. I did learn of the pattern before I knew how it was called when working with Spring Framework and Symfony, which often uses a variation where you first call supports() method that returns a boolean and if it return true you call the aggregate method.
The only thing you can do wrong with this pattern is that one of the chains is relying on a state change in a previous chain as those dependencies are easy to miss. I prefer a chain to be functional and immutable.
1:36 - Reverse impl (video about impl reverse that run once)
Great video, as always. 🙌 Greetings from InterVenture.
Really interesting video - thanks for sharing. Also, a very good and practical example. I was following along, but used Java 17 for the implementation. To my surprise, I realised that Java already includes the Chain of Responsibility in its Comparator class, via the `.thenComparing()` method. Nice. 🙂
Now that you said it, I think I remember it does. Java has one practical feature that i like a lot - functional interfaces. So many interfaces only expose one method, and the ability to use lambdas and interfaces interchangeably is really useful.
Neat! A nice reminder og a useful pattern -- thanks!
Hi, Thank u for the interesting video. Should we mentioned that the same can be achieved using LINQ? If yes, should we consider LINQ chaining as the Chain of Responsibility?
If the nodes are organized into an IEnumerable, then LINQ is a viable option. Though, you must take care to construct a correct expression. In the example from the video, nodes are NOT ordered into a sequence.
Nice and practical video.
However, in C# this can happen using linq. Is linq actually doing an implementation of "Chain of Responsibility" ?
Or it the the Comparer itself that is "chained" and it be used both in List.Sort and IEnumerable.OrderBy() ?
It depends on what you mean by "doing an implementation". If you consider the example implementation from the GoF pattern, then it is only one possibility. It is far from being the only one, let alone the best implementation one can come up with.
In my opinion, design patterns are not their implementations, but the externally visible interaction, usually - but not always - implemented via object injection.
In the case of the Chain of Responsibility, there are two principal implementations that correspond to linked list vs. array list, with all pros and cons of both approaches.
Using LINQ operators such as SkipWhile, First, etc. makes it no different than the CoR implementation from the GoF book, which is based on object chaining.
So, the answer to your question does LINQ implement CoR is (in precise terms): no, it doesn't. But the caller could not tell the difference anyway, due to encapsulation.
@@zoran-horvat Thank you Zoran for you answer. It totally makes sense your "point of you" about what design patterns really are and teach us this way of thinking.
I already bought your Udemy course on this topic and I look forward to studying it in detail.
How would you do the the sorting of a collection in C# ? Would you use the linq support to "Chain' method calls like "OrderByDescending(comparer1).ThenBy(comparer2)..."
*OR* "OrderBy(comparer1.Then(comparer2))" which is your example of CoR (let's imagine that we don't want to use List.Sort())?
Is it a matter of preference or what ?
And by the way, I am not aware what the example implementation from the GoF book is :)
@@MrJonnis13 The CoR implementation in GoF is literally a linked list of objects. I have used CoR several times in practice and I always flattened that into a list for performance gains (which were measurable).
Regarding sorting, from what I have seen in the LINQ source code, OrderBy and ThenBy methods are heavily optimized and I see no reason to avoid them. My guess is that they could even perform better than the custom chained comparer. The reason for having the chained comparer is for the sake of sorting methods that can only accept one IComparer, such as the List's Sort method.
@@zoran-horvat Thanks again Zoran, I will be following your content from now on :)
wonderful