High Definition Standard Definition Theater
Video id : C1pbRp1EQdk
ImmersiveAmbientModecolor: #e5e7e6 (color 2)
Video Format : (720p) openh264 ( https://github.com/cisco/openh264) mp4a.40.2 | 44100Hz
Audio Format: 140 ( High )
PokeEncryptID: 899ea87bb116a9de43c8a1fd594fb9603b5d199b5ef849f93f2add3e8c59b6bc0ac81379fd209c4f492699172dc1ce16
Proxy : cal1.iv.ggtyler.dev - refresh the page to change the proxy location
Date : 1732653368500 - unknown on Apple WebKit
Mystery text : QzFwYlJwMUVRZGsgaSAgbG92ICB1IGNhbDEuaXYuZ2d0eWxlci5kZXY=
143 : true
Lambdas Almost Killed the Strategy Pattern
Jump to Connections
15,183 Views • Jun 26, 2024 • Click to toggle off description
Watch the long video:    • Master the Design of Classes  

Become a sponsor to access source code ► www.patreon.com/zoranhorvat
Join Discord server with topics on C# ► codinghelmet.com/go/discord
Enroll course Beginning Object-Oriented Programming with C# ► codinghelmet.com/go/beginning-oop-with-csharp
Subscribe ►    / @zoran-horvat  

When was the last time you saw the Strategy pattern?
Here it is.
Imagine you need to process the state in some method.
There can be many ways to do it, and you cannot tell the right one up-front.
That's easy!
Ask for the Strategy.
Define an interface you want.
This interface transforms a string into a string.
Inject it into the class and use it in the place where you want to.
The ball is in the caller's yard.
They must provide concrete implementations and inject one each time they use your class.
That is great.
This is one of the best patterns in existence.
But the times have changed.
Why so much code when we can request a simple Func delegate?
Inject a lambda and remove all these verbose types.
Learn about object design from the long video.
Here, you saw how lambdas almost eradicated the Strategy pattern.
Think for yourself.


▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬
👨 About Me 👨
Hi, I’m Zoran, I have more than 20 years of experience as a software developer, architect, team lead, and more. I have been programming in C# since its inception in the early 2000s. Since 2017 I have started publishing professional video courses at Pluralsight and Udemy and by this point, there are over 100 hours of the highest-quality videos you can watch on those platforms. On my YouTube channel, you can find shorter video forms focused on clarifying practical issues in coding, design, and architecture of .NET applications.❤️
▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬
⚡️COPYRIGHT NOTICE:
The Copyright Laws of the United States recognize a “fair use” of copyrighted content. Section 107 of the U.S. Copyright Act states: “Notwithstanding the provisions of sections 106 and 106A, the fair use of a copyrighted work, including such use by reproduction in copies or phono records or by any other means specified by that section, for purposes such as criticism, comment, news reporting, teaching (including multiple copies for classroom use), scholarship, or research, is not an infringement of copyright." This video and our youtube channel, in general, may contain certain copyrighted works that were not specifically authorized to be used by the copyright holder(s), but which we believe in good faith are protected by federal law and the Fair use doctrine for one or more of the reasons noted abov
Metadata And Engagement

Views : 15,183
Genre: Science & Technology
Uploaded At Jun 26, 2024 ^^


warning: returnyoutubedislikes may not be accurate, this is just an estiment ehe :3
Rating : 4.901 (21/831 LTDR)

97.54% of the users lieked the video!!
2.46% of the users dislieked the video!!
User score: 96.31- Overwhelmingly Positive

RYD date created : 2024-11-23T02:54:21.796585Z
See in json
Tags
Connections
Nyo connections found on the description ;_; report an issue lol

36 Comments

Top Comments of this video!! :3

@ebbergemann

4 months ago

There hits a point with these lambdas where the amount of code that doesn't describe itself is quite excessive. One ventures into an application and finds themselves having to debug each and every lambda in order to understand what they are doing.

The extra text in those strategy/interface implementations contain valuable information for other developers. That is, it tells them what the code is doing.

A simple s.ToUpper() is one thing, but when the lambdas are quite long and don't rely on enough named functions describing themselves within the lambdas, the code becomes a mess.

The measure of good code design is not how few lines you can fit it in, but how quickly someone can understand it. Sometimes more code can be understood faster.

32 |

@brendonlantz5972

4 months ago

I find lambas to be useful sometimes in conjunction with the factory pattern as well. That way the factory can register creation logic by name or ID and be more dynamic as was needed in my case.

16 |

@WDGKuurama

4 months ago

Injecting delegates is also nice in my opinion. When you need it somewhere else you can directly get it from DI.

10 |

@nickbarton3191

4 months ago

I'm doing both, if there many functions then an Interface is easiest. But injection we do all the time, for dependency inversion so we can create unit tests.

4 |

@magnusm4

2 months ago

I love using lambda delegates in my hierarchical state machine.
Instead of adding each state's interface and looping through them.
I just make any function I want and subscribe it to the machine's delegates while passing the user as the context for information.

|

@valentinasler155

2 months ago

It is still a strategy pattern although implemented a bit differently.

1 |

@Rick-mf3gh

4 months ago

The 'lambda' approach can get really messy really quickly. It can also be very difficult to unit test.

2 |

@etiennelemieux472

4 months ago

I'm not convinced. When you have an implementation of ITransform, its ctor can accept parameters to finetune its behavior. The lambda option does the trick in simple cases, and as soon as it doesn't you have to go back to Strategy, and change lots of code.
Strategy is way more flexible IMHO

1 |

@damianradinoiu4314

4 months ago

When hiding implementation use Strategy. When dynamically defining the behavior use Delegates.

|

@milosmrdovic7233

3 months ago

There is, unfortunately, no silver bullet when it comes to software engineering. The main drawback of the strategy pattern VS passing lambdas is the verbosity of the code. The big advantage of the strategy pattern, however, is the ability to directly unit test the strategies as well as the opportunity to better express the intent. Which one should you use depends on the problem you are trying to solve. Unless I'm dealing with a very low level code that I have the opportunity to thoroughly test on higher levels of abstraction, I usually opt for strategies.

|

@umdi3337

4 months ago

Another bold claim. It seems your channel has evolved into being more speculative than informative.

|

Go To Top