Remove Separate Concerns From a Class and Make It Favor SRP Again
ฝัง
- เผยแพร่เมื่อ 26 ก.ค. 2024
- Download the source code: / source-code-for-87512006
Classes that start out simple often fall victim to the creep of complexity in a very peculiar manner. Separate concerns can sneak into a class, leading to a bloated mess of code that's hard to understand and maintain. What once was sleek and elegant turns into a tangled web.
In this video, we dive deep into this all-too-common problem to uncover its sources and explain the cure for it. We will start by dealing with issues related to implementing Composite and Decorator patterns, continue with optimizing the performance of the resulting object composition, all the way through to find that all those separate concerns, though mandatory, have caused bloat in what used to be a concise class, ruining its elegance beyond recognition.
You will learn to utilize the power of extension methods as your ally in maintaining the Single Responsibility Principle and keeping your code clean and effective.
Thank you so much for watching! Please like, comment & share this video as it helps me a ton!! Don't forget to subscribe to my channel for more amazing videos and make sure to hit the bell icon to never miss any updates.🔥❤️
✅🔔 Become a patron ► / zoranhorvat
✅🔔 Subscribe ► / @zoran-horvat
⭐ 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...
▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬
⭐ CONNECT WITH ME 📱👨
🌐Become a patron ► / zoranhorvat
🌐Buy me a Coffee ► ko-fi.com/zoranhorvat
🗳 Pluralsight Courses ► codinghelmet.com/go/pluralsight
📸 Udemy Courses ► codinghelmet.com/go/udemy
📸 Join me on Twitter ► / zoranh75
🌐 Read my Articles ► codinghelmet.com/articles
📸 Join me on LinkedIn ► / zoran-horvat
▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬
👨 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 TH-cam channel, you can find shorter video forms focused on clarifying practical issues in coding, design, and architecture of .NET applications.❤️
▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬
⚡️RIGHT 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 above.
⭐For copyright or any inquiries, please contact us at zh@codinghelmet.com
#csharp #dotnet #objectorientedprogramming - วิทยาศาสตร์และเทคโนโลยี
Download source code from Patreon ► www.patreon.com/posts/source-code-for-87512006
Watch my course Beginning Object-Oriented Programming with C# at Udemy ► codinghelmet.com/go/beginning-oop-with-csharp
Watch my other courses at Udemy ► codinghelmet.com/go/udemy
Watch my other courses at Pluralsight ► codinghelmet.com/go/pluralsight
I want a Zoran in my team!!!
I'd go with intermediate solution, more pragmatic, balanced and safe, imho :) Thanks for the great video as always 👍😊
That also makes sense. I'm fine with anything that will help the one who reads the code to orientate and figure what it does and, more importantly, to see whether it does what is requested or not.
"Ease my conscience", boy do I know that feeling.
Fantastic demo, thank you. Refactoring ASMR.
Great one.
Thanks!
Great video!
Thanks!
@@zoran-horvat How do you balance making too many classes out of everything so you can't see the forest for all the trees? Hard balance imo. Principles are good but when trying to make too many classes things can also get messy. Thoughts?
@@dzllz Group them into sub-namespaces. You would never need to expand them in the project tree, except when working on those classes precisely, and all you would ever see is the set of root abstractions and factories at the upper-level namespace.
I am pretty much using these concepts in my pet projects, and honestly, they help a lot to simplify. However, I am going to disagree with the last refactoring. I have found it is easier to navigate and understand the code when related concerns that are not shared are in the same scope (either file or class) Also, I haven't found particularly practical to enforce "must do a single thing" in all situations, but rather I prefer to accomplish a single goal, which might involve multiple "concerns" within the same scope (typically IO operations) In any case, all of these are great techniques to add to the toolbox!
That is also fine. I plan to make an additional video on DSLs, which would add more meaning to the Last refactoring step. Once it becomes a part of a larger suite of methods, then accepting and using methods like that one would feel more natural in that model.
@@zoran-horvat looking forward that video!
I wouldn't feel comfortable exposing the ctor as well 😅
I don't think there is anything wrong with that. There are a couple of reasons in favor of hiding a constructor and exposing a static factory function instead of the constructor, but if none applies, then the constructor remains.
One is to return an optional or nullable object in the smart constructor style. Another is when returning a base type (typically an interface) and then choosing whether to instantiate that class or some other, based on the arguments.