This Decorator Pattern Implementation Will Make Your Day!

preview_player
Показать описание

Decorator is one of the fundamental design patterns. It has wide range of applications in programming, though we might sometimes feel it is neglected.
This video is analyzing the problem we encounter when a method receives an IComparer, but what we need is its reverse. Like sorting the data vs. sorting descending. All we have is an IComparer that compares in ascending order, but no opposite one.
In this video, you will learn how to apply the Decorator design pattern to solve problems like this one. We will create a special-purpose IComparer which reverses the decision of another IComparer, even without knowing how it works.
Before the end, we will even design an optimizing static factory for the reversing comparer, so that if a comparer is reversed two times in a row, all decoration is removed from it so to save execution time.

Chapters:
00:00 Intro
01:01 Inventing the Decorator pattern
02:23 IComparable decorator used by List
03:22 Implementing the ReverseComparer class
05:05 Implementing the optimized decorator factory
08:02 Using the decorator

Learn more from video courses:

Other videos on this channel you may be interested in watching:
Рекомендации по теме
Комментарии
Автор

I've learned so much from your videos over the years Zoran. Your videos on Pluralsight were some of the primary sources of me beginning to really grasp design patterns. And I've enjoyed the way you teach, you make it exciting!

KA-wfrg
Автор

We cannot thank you enough for the wonderful videos and explanations!

coderabsolute
Автор

Great work Zoran, I loved the simplicity

willcasey
Автор

I have seen your plural courses also, to make code readable you make use of extension method extensively.
If you could compile separate course/video to teach technique to improve readability that would be awesome.
5* for this video👍

swapniltayade
Автор

if you need to sort by another property in a comparison when the result is 0, is there a way to avoid the reverse comparer to reverse this second property too? like i want to sort by type and then the name. The type should get reverse but not the name.

ghevisartor
Автор

Has to watch this three times to catch the nuances.
Never seen an extension method made by a factory before.
Not thread safe ?

nickbarton
Автор

Very energetic, thanks, i have a question

Does decorator have to be always static

santosh
Автор

Thanks Zoran. Are you planning on making a follow up to your Object Oriented C# course on Udemy?

superpcstation
Автор

have you considered practical f# libraries course? how to make f# libraries that can be used by c# front ends?

vbachris
Автор

Great video Mr.Zoran. Would like to know if your functional c# course in plural sight or it's equivalent course is available in udemy

deva
Автор

Hey Zoran, I love your video and enthusiasm so much. But as a Kotlin dev this code repulses me, because in Kotlin those 18 lines would just be half a line in a functional programming style.

chh
Автор

Explain about prevent reverse 2x using decorator

ivandrofly
join shbcf.ru