Chain of Responsibility to the Rescue!

  Рет қаралды 12,897

Zoran Horvat

Zoran Horvat

Күн бұрын

Пікірлер: 24
@zoran-horvat
@zoran-horvat Жыл бұрын
Become a patron and get access to source code and exclusive live streams: www.patreon.com/posts/chain-of-to-81381632
@marklord7614
@marklord7614 2 жыл бұрын
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.
@sulmarpl
@sulmarpl 5 ай бұрын
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.
@LassePi
@LassePi 2 жыл бұрын
Your pluralsight and udemy courses are fire! Thanks for all the great content!
@real_logicmonk
@real_logicmonk 2 жыл бұрын
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.
@superpcstation
@superpcstation Жыл бұрын
He made another functional programming course on pluralsight. it's on my watch list.
@real_logicmonk
@real_logicmonk Жыл бұрын
Functional c# 10 - mine too :)
@ivandrofly
@ivandrofly Жыл бұрын
1:36 - Reverse impl (video about impl reverse that run once)
@krccmsitp2884
@krccmsitp2884 Жыл бұрын
A very nice real-world example of the pattern in use.
@10199able
@10199able 2 жыл бұрын
I like how practical your examples are!
@PieJee1
@PieJee1 Ай бұрын
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.
@AhmadMazen-i9t
@AhmadMazen-i9t 5 ай бұрын
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.
2 жыл бұрын
Great video, as always. 🙌 Greetings from InterVenture.
@andersjuul8310
@andersjuul8310 10 ай бұрын
Neat! A nice reminder og a useful pattern -- thanks!
@therealgraeme
@therealgraeme Жыл бұрын
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. 🙂
@zoran-horvat
@zoran-horvat Жыл бұрын
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.
@alexlo5655
@alexlo5655 Жыл бұрын
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?
@zoran-horvat
@zoran-horvat Жыл бұрын
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.
@MrJonnis13
@MrJonnis13 Жыл бұрын
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() ?
@zoran-horvat
@zoran-horvat Жыл бұрын
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.
@MrJonnis13
@MrJonnis13 Жыл бұрын
@@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 :)
@zoran-horvat
@zoran-horvat Жыл бұрын
@@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.
@MrJonnis13
@MrJonnis13 Жыл бұрын
@@zoran-horvat Thanks again Zoran, I will be following your content from now on :)
@janoslaszlo3272
@janoslaszlo3272 3 ай бұрын
wonderful
Use Null Object Pattern in Your Rich Domain Model
13:16
Zoran Horvat
Рет қаралды 12 М.
IL'HAN - Qalqam | Official Music Video
03:17
Ilhan Ihsanov
Рет қаралды 700 М.
“Don’t stop the chances.”
00:44
ISSEI / いっせい
Рет қаралды 62 МЛН
Tuna 🍣 ​⁠@patrickzeinali ​⁠@ChefRush
00:48
albert_cancook
Рет қаралды 148 МЛН
Леон киллер и Оля Полякова 😹
00:42
Канал Смеха
Рет қаралды 4,7 МЛН
Master the Power of Composite Pattern in Rich Domain Modeling
14:07
Combine Design Patterns To Reveal Their Greatest Power
14:21
Zoran Horvat
Рет қаралды 8 М.
Decorator Design Pattern Explained (Java)
5:08
ImmaculateCoder
Рет қаралды 83
This Decorator Pattern Implementation Will Make Your Day!
9:37
Zoran Horvat
Рет қаралды 12 М.
Favor Method Chaining Over Nested Calls | Clean Code
10:23
Zoran Horvat
Рет қаралды 26 М.
Build Your Own Option Type in C# and Use It Like a Pro
18:31
Zoran Horvat
Рет қаралды 15 М.
The Fastest Way to Modify a List in C# | Coding Demo
10:30
Zoran Horvat
Рет қаралды 26 М.
How to Avoid Null Reference Exceptions: Optional Objects in C#
18:13
Stop Creating Class Hierarchies! (If You Haven't Already)
7:44
Zoran Horvat
Рет қаралды 13 М.
IL'HAN - Qalqam | Official Music Video
03:17
Ilhan Ihsanov
Рет қаралды 700 М.