Тёмный

Chain of Responsibility to the Rescue! 

Zoran Horvat
Подписаться 25 тыс.
Просмотров 11 тыс.
50% 1

Become a patron and get access to source code and exclusive live streams: / chain-of-to-81381632
Chain of Responsibility is one of the less-frequently used design patterns, but also one of the most useful patterns. It helps compose simple decision-making objects into a chain structure, so that the objects get the opportunity to decide in order of their appearance. The first object to successfully complete the task gets all the credits, and its response becomes the result of the entire chain.
That is the theory, and in this video you will learn the practical aspects of applying and implementing the Chain of Responsibility design pattern. We will address the issue of combining simple IComparer instances to build a multi-level sorting comparer object which can be used in contexts where only one IComparer object can be supplied.
Video courses on design patterns:
Design Patterns in C# Made Simple ► codinghelmet.com/go/design-pa...
Refactoring to Patterns ► codinghelmet.com/go/refactori...
Creating Objects ► codinghelmet.com/go/tactical-...
Managing Responsibilities ► codinghelmet.com/go/tactical-...
Control Flow ► codinghelmet.com/go/tactical-...
Chapters:
00:00 Intro
01:10 Understanding the need for the Chain of Responsibility
02:55 Implementing the Chain of Responsibility
05:20 Using the Chain of Responsibility
06:53 Implementing reusable partial comparers
Learn more from video courses:
Beginning Object-oriented Programming with C# ► codinghelmet.com/go/beginning...
Collections and Generics in C# ► codinghelmet.com/go/collectio...
Making Your C# Code More Object-oriented ► codinghelmet.com/go/making-yo...
Other courses at Pluralsight ► codinghelmet.com/go/pluralsight
Other courses at Udemy ► codinghelmet.com/go/udemy
Other videos on this channel you may be interested in watching:
Using GitHub Copilot to Write Complex Code | Step-by-step Tutorial ► • Using GitHub Copilot t...
Coding with GitHub Copilot - Beginner to Master | VS Code Demo ► • A Comprehensive Guide ...
What is Covariance and Contravariance in C# ► • What is Covariance and...
How to Initialize a Clean ASP.NET Core Project with Entity Framework Core and Identity ► • How to Initialize a Cl...
The Null Conundrum: A Guide to Optional Objects in C# ► • How to Avoid Null Refe...
#designpatterns #dotnet

Наука

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

 

27 июн 2024

Поделиться:

Ссылка:

Скачать:

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

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 20   
@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 Год назад
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.
@LassePi
@LassePi Год назад
Your pluralsight and udemy courses are fire! Thanks for all the great content!
@krccmsitp2884
@krccmsitp2884 7 месяцев назад
A very nice real-world example of the pattern in use.
@real_logicmonk
@real_logicmonk Год назад
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 :)
@10199able
@10199able Год назад
I like how practical your examples are!
@ivandrofly
@ivandrofly 9 месяцев назад
1:36 - Reverse impl (video about impl reverse that run once)
@andersjuul8310
@andersjuul8310 4 месяца назад
Neat! A nice reminder og a useful pattern -- thanks!
Год назад
Great video, as always. 🙌 Greetings from InterVenture.
@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 11 месяцев назад
@@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 11 месяцев назад
@@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 11 месяцев назад
@@zoran-horvat Thanks again Zoran, I will be following your content from now on :)
Далее
Use Null Object Pattern in Your Rich Domain Model
13:16
LISA - ROCKSTAR (Official Music Video)
02:48
Просмотров 25 млн
🎤Пою РЕТРО Песни ✧˖°
3:04:48
Просмотров 1,7 млн
Composite - Design Patterns in 5 minutes
4:24
Manage Nulls Like a Boss and Never Fail!
21:43
Просмотров 11 тыс.
5 Design Patterns That Are ACTUALLY Used By Developers
9:27
17 Pieces of C# Syntax That Make Your Code Short
12:41
Why Use Design Patterns When Python Has Functions?
23:23
FullHD в 8К БЕЗ ПОТЕРЬ? | РАЗБОР
20:42
Main filter..
0:15
Просмотров 11 млн