Тёмный

Design Patterns: Open Closed Principle Explained Practically in C# (The O in SOLID) 

IAmTimCorey
Подписаться 415 тыс.
Просмотров 214 тыс.
50% 1

When you are writing code, are you doing it right? That is a question that worries a lot of people, and it should probably at least be something every developer thinks through. Design patterns are best-practice concepts that we can implement into our code to make it better in some way. Think of them as guardrails that keep our code safe. In this video, we are going to look at the second entry in the famous SOLID principle. The O stands for Open Closed Principle. We are going to dive into what it means, how it should change our programming practices, and how far we should take it.
Newsletter signup (with exclusive discounts): signup.iamtimcorey.com/ (your email will be kept safe and you will not be spammed).
Source Code: leadmagnets.app/?Resource=OIn...
0:00 - Intro
1:43 - Code behind demo application
5:36 - Open Closed Principle: when to apply
6:18 - Introducing changes in existing code base
18:20 - Identify the issues
21:40 - Implementing OCP: Use of interfaces
38:32 - Implementing OCP: Recap
40:46 - Summary
42:05 - Organizing the code base
43:55 - Note on Namespaces in folder structure
46:50 - Concluding remarks

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

 

1 июл 2024

Поделиться:

Ссылка:

Скачать:

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

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 631   
@cyberblogger3900
@cyberblogger3900 3 года назад
Your explanation is SOLID! Thank you.
@IAmTimCorey
@IAmTimCorey 3 года назад
Glad it was helpful!
@samuelpage5409
@samuelpage5409 Год назад
One thing I really appreciate about your videos is that you speak clearly enough for RU-vid's auto-generated captions to work accurately. Great information, thank you for the video!
@IAmTimCorey
@IAmTimCorey Год назад
You are welcome.
@RP-dy5mu
@RP-dy5mu 2 года назад
Hey Tim, I was approached by a company for a senior position for the first time in my life, and the tech interview is tomorrow. I'm just going over the SOLID principles again and realized I never truly understood any of them. I'll probably get obliterated tomorrow, but still thanks a lot for this explanation! We use similar approaches in our current codebase, but now I'm able to at least put a name to the face of this principle.
@IAmTimCorey
@IAmTimCorey 2 года назад
Excellent! Best wishes on the interview.
@markdee3506
@markdee3506 2 года назад
How did the interview go?
@wisbenah
@wisbenah 6 лет назад
Like Kaushik S, said you're the best when it comes to presentations. You always assume your audience may not know much or anything about the topic, so you go in details along the way. That's a wonderful approach. Thanks!
@IAmTimCorey
@IAmTimCorey 6 лет назад
I appreciate the kind words. I'm glad you appreciate my approach.
@nathanunderbsd5972
@nathanunderbsd5972 5 лет назад
This is not only MVP, I make it higher than MVP.
@DepressionAlgorithm
@DepressionAlgorithm 6 лет назад
I really like these videos. I particularly appreciate the fact you show the actual implementation by showing/writing the code in a way that isn't overly abstract and simplified. Thanks a lot!
@IAmTimCorey
@IAmTimCorey 6 лет назад
You are welcome.
@GuySymonds1
@GuySymonds1 4 года назад
Loved this video, I have watched many videos and read many more articles on SOLID and C# and I haven't found an explanation that is as clear and concise as this one.
@IAmTimCorey
@IAmTimCorey 4 года назад
I am glad you enjoyed it.
@shawnmofid7131
@shawnmofid7131 5 лет назад
Thank you. You make sure to explain the reason behind every decision, and all the other details. I watch some a number of times, and am so glad to be learning C# and watching the contents of this channel.
@IAmTimCorey
@IAmTimCorey 5 лет назад
I appreciate the kind words.
@pedroluiz8019
@pedroluiz8019 3 года назад
Thank you for this series. I love the fact that you actually make a interesting example instead of only staying on the theory realm.
@tomthelestaff-iamtimcorey7597
@tomthelestaff-iamtimcorey7597 3 года назад
Tim has real world experience and thinks its important to share it. Viewers seem to agree.
@stevencruz978
@stevencruz978 3 года назад
Great execution Tim, thank you! I've definitely been violating the O/C principle for a while now, but not anymore. I'm seeing more of why interfaces are a godsend.
@IAmTimCorey
@IAmTimCorey 3 года назад
Excellent!
@luismendez9436
@luismendez9436 4 года назад
Agree with previous comments...exactly what the type of tutorials one needs. Thanks for this.
@IAmTimCorey
@IAmTimCorey 4 года назад
Glad it was helpful!
@nikinikolov6570
@nikinikolov6570 5 лет назад
Great job. Love that the application is not some abstract project. Making it as close as you can to real life helps to more easily understand the SOLID design pattern. Thank you.
@IAmTimCorey
@IAmTimCorey 5 лет назад
You are most welcome. Thanks for watching.
@fadidib8516
@fadidib8516 2 года назад
I enjoy watching ur videos, it shows a lot of in-depth stuff that we miss, and that u explain what are you doing in order not to get lost.
@IAmTimCorey
@IAmTimCorey 2 года назад
Excellent!
@tonybapuji5956
@tonybapuji5956 2 года назад
Another Great video from Tim. Tim looks at things step by step to show this principle and the important practical benefits. Also, lots of good tips along the way to save you getting caught in traps unexpectedly, thanks Tim.
@IAmTimCorey
@IAmTimCorey 2 года назад
You are most welcome. Thanks for watching.
@rubyelephant5922
@rubyelephant5922 9 месяцев назад
Excellent work, neatly and concisely explained I wish my University had a teacher like you
@IAmTimCorey
@IAmTimCorey 9 месяцев назад
I am glad it was helpful.
@Muuuzzzi
@Muuuzzzi 5 лет назад
I like the way you teach, it's easy to follow your thought process, the explanation of why and how, and not too many presumptions.... good work!
@IAmTimCorey
@IAmTimCorey 5 лет назад
I am glad you are enjoying the content and my style.
@p199a
@p199a 6 лет назад
I love this videos it so hard to find anything more than basic tutorials and this are just amazing. I understend everything, examples are practical and simple.
@IAmTimCorey
@IAmTimCorey 6 лет назад
Excellent!
@dvalmont07
@dvalmont07 5 лет назад
Thank you for share your wisdom. This isn't an easy concept, but your class was crystal clear. Love from Brazil!
@IAmTimCorey
@IAmTimCorey 5 лет назад
You are most welcome. Thanks for watching.
@noextrasugar
@noextrasugar Год назад
Great teaching style Tim, so glad I've found this channel!💛💪
@IAmTimCorey
@IAmTimCorey Год назад
Awesome, thank you!
@soucianceeqdamrashti8175
@soucianceeqdamrashti8175 4 года назад
Really good and well explained with the code. Excellent work! Loving the series.
@IAmTimCorey
@IAmTimCorey 4 года назад
Thank you!
@electrocatalyst
@electrocatalyst Год назад
Thanks for explaining this principle. All the other videos which try to explain it in 3 minutes fail to explain it completely.
@IAmTimCorey
@IAmTimCorey Год назад
You are welcome.
@alebado8664
@alebado8664 4 года назад
Wow, you amazed me, you have amazing content, very informative and interesting to watch, and you even keep answering question after month have passed. Great job man, you are wonderful person!
@IAmTimCorey
@IAmTimCorey 4 года назад
I appreciate the kind words.
@ajitsaharan9445
@ajitsaharan9445 3 года назад
I have no word....its awesome, your tutorials changed my coding style.....Thank you Sir...Super Love for You
@IAmTimCorey
@IAmTimCorey 3 года назад
I am so glad they were helpful.
@maatsa6526
@maatsa6526 Год назад
Hi Tim! Thanks for a good video! Just wanted to comment - that while I do think you're explaining the concept of the open / closed principle good with your example. I also think it shows as why you should be cautious about implementing this principle in the real world. I consider the amount of complexity added to the application a worser tradeoff than a bug or two in the long term. The bugs can be easily fixed when identified while the added complexity might be there forever :)
@TundeAjao
@TundeAjao 6 лет назад
Great Tim .... you are doing a great job in making C# easier for people
@IAmTimCorey
@IAmTimCorey 6 лет назад
Thanks!
@ultroai
@ultroai 3 года назад
Great and simple explanation of rather hard to get principle. Thanks for it.
@longuinni
@longuinni 6 лет назад
Great video Tim. Easy to understand, good examples... Thanks for sharing that knowledge!!
@IAmTimCorey
@IAmTimCorey 6 лет назад
Thanks. I was hoping it was easy to understand. I was concerned it was getting a bit complex. I wanted to get past the examples that are simple but don't really apply to the real world, but that meant upping the complexity. Glad it came through clearly.
@jagjotjaggi
@jagjotjaggi 5 лет назад
Very nice video tutorials about the SOLID principles. Really liked and enjoyed. Could not refrain myself from subscribing your channel. Would love to see new things. Thank you very much Tim. Keep it up!!!!!
@IAmTimCorey
@IAmTimCorey 5 лет назад
I appreciate the kind words. I'm glad you are enjoying my content.
@chrisrey2516
@chrisrey2516 4 года назад
These are things my degree has never taught me. Practical Software Engineering. Thank you for your videos. This is what separates juniors from more experienced programmers and you are helping me with that step! I'm applying these to code in my current job
@IAmTimCorey
@IAmTimCorey 4 года назад
Great to hear!
@bharathyadav3614
@bharathyadav3614 6 лет назад
Ever since I started following you on RU-vid, I’ve become a big fan of your teaching methods. I’m a WPF Developer and I really wanted to know more about Design Patterns. Thanks to your video tutorial using practical examples. Looking forward for upcoming videos on Design Patterns. More power to you!
@IAmTimCorey
@IAmTimCorey 6 лет назад
Awesome! I'm glad you're enjoying the series.
@vinuhosanagar1
@vinuhosanagar1 6 лет назад
Hi Bharath, I'm also WPF developer. Which company you work for?. I stay in Bangalore. Can we connect on vinaypalaksha1@gmail.com
@markyap4755
@markyap4755 4 года назад
Hi Tim, thanks for the great videos. I am new and thus these videos are a great help. Plan to enroll in your courses next.
@IAmTimCorey
@IAmTimCorey 4 года назад
I am glad they are so helpful.
@HanselGraciadelBusto
@HanselGraciadelBusto 3 года назад
Simple, clear and useful, as usual. Thanks!
@IAmTimCorey
@IAmTimCorey 3 года назад
You're welcome!
@ksenthil20
@ksenthil20 5 лет назад
Tim, Thank you for making this video. Very clear explanation with examples.
@IAmTimCorey
@IAmTimCorey 5 лет назад
You are most welcome. Thanks for watching.
@RiderInHell
@RiderInHell 3 года назад
Great explanation. And I finally understood the uses for interfaces. I mean, not how to use them for the advantages of using them. I'm looking forward to start implementing them from now on! Thanks, Tim. :D
@IAmTimCorey
@IAmTimCorey 3 года назад
Glad it was helpful!
@davidsuarez5317
@davidsuarez5317 4 года назад
HUGE EXPLANETION!! Like a lot your videos. Greetings from Cuba
@IAmTimCorey
@IAmTimCorey 4 года назад
Thanks!
@101114104
@101114104 6 лет назад
Great instruction. Excellent, practical but not incomprehensible example app/code! Thanks!
@IAmTimCorey
@IAmTimCorey 6 лет назад
I am glad you found it useful.
@eliedh8271
@eliedh8271 5 лет назад
you really do clear up the confusion and the frustration around learning c#. xD
@IAmTimCorey
@IAmTimCorey 5 лет назад
Awesome! That's the goal. I'm glad you feel like I am accomplishing it.
@ryanfreeman663
@ryanfreeman663 2 года назад
Thank you very much for this video! This was very well explained, I have been able to make good notes from it, and I now feel ready to implement this principle in my future projects.
@IAmTimCorey
@IAmTimCorey 2 года назад
Glad it was helpful!
@AnalogGame
@AnalogGame 3 года назад
I really like the clear explanation and the examples used. Have a better understanding of open Closed Principle
@IAmTimCorey
@IAmTimCorey 3 года назад
Glad it helps.
@franciscooliveira8585
@franciscooliveira8585 9 месяцев назад
Software entites( classes, modules, functions, etc.) should be OPEN FOR EXTENSION, but CLOSED FOR MODIFICATION. With the Open Closed Principle, the code is more robust and more future proof. I understood it all! Thank you Tim!
@IAmTimCorey
@IAmTimCorey 9 месяцев назад
I am glad it was helpful.
@davidmipancito
@davidmipancito 5 лет назад
Practice! Practice! Practice its going to be my goal to be better programming, Thnks a lot Tim for this great video tutorial!
@IAmTimCorey
@IAmTimCorey 5 лет назад
Yep, practice is really important. Glad you enjoyed the video.
@soubarnobanerjee8257
@soubarnobanerjee8257 2 года назад
This basically kinda explains why interface is needed. Also what happens if there was no interface in a project!! Learnt a lot. When you first taught about interface and the reasons behind using them, it was actually telling about this OCP. Now it's all clear
@IAmTimCorey
@IAmTimCorey 2 года назад
I am glad it is clear now.
@fairozahmed6888
@fairozahmed6888 4 года назад
A big thank you for your awesome tutorials. God bless you. Love and Respect from India.
@IAmTimCorey
@IAmTimCorey 4 года назад
You are most welcome.
@iam_Raavanan
@iam_Raavanan 3 года назад
Wowwww!!! What an amazing explanation. Highlight is practical examples, which makes this sooooooo goooooood!!!!
@IAmTimCorey
@IAmTimCorey 3 года назад
Glad it was helpful!
@iam_Raavanan
@iam_Raavanan 3 года назад
@@IAmTimCorey Is there any possibility for doing videos in C++. It would be really helpful. Consider it as request.
@brianyoung3876
@brianyoung3876 5 лет назад
Thank you for explaining these principles. Ive done software dev for a fortune 500 company for 3 years and I realized we dont use solid. At. All. Our architecture is gross. Ive been looking to sharpen our apps and these have been a great starting point. Thanks again!
@IAmTimCorey
@IAmTimCorey 5 лет назад
Yep, that is fairly common. I'm glad these will be useful to you.
@harshpatel-wr1jl
@harshpatel-wr1jl 2 года назад
again great video TimCorey
@IAmTimCorey
@IAmTimCorey 2 года назад
You are welcome.
@chriscatignani8206
@chriscatignani8206 2 года назад
Really great series..."As always"...I come away learning something new.
@IAmTimCorey
@IAmTimCorey 2 года назад
Glad to hear it!
@StephenOwen
@StephenOwen 4 года назад
Really crisp audio in this one, Tim. Very easy to follow along with ( I know you mentioned trying to slow down a bit in your videos before). Well this one was great from that regard!
@IAmTimCorey
@IAmTimCorey 4 года назад
Glad it was clear.
@pawanshetty4795
@pawanshetty4795 3 года назад
Awesome approach of explanation - step by step and reasons presented why not to follow a specific approach.
@IAmTimCorey
@IAmTimCorey 3 года назад
Glad it was helpful!
6 лет назад
Thanks Tim! This video I liked a lot and I learned a lot from it.
@IAmTimCorey
@IAmTimCorey 6 лет назад
Awesome! I love it when people learn something from my videos.
@bsouzafilipe
@bsouzafilipe 2 года назад
You made a helpful explanation. Thank you, it was easier to understand.
@tomthelestaff-iamtimcorey7597
@tomthelestaff-iamtimcorey7597 2 года назад
Glad you found it helpful. Thanks for sharing.
@dowdag
@dowdag 5 лет назад
Great video - you got through the video with out mentioning polymorphic once :)
@IAmTimCorey
@IAmTimCorey 5 лет назад
I try to avoid confusing words that don't add to the discussion.
@lindaporsius
@lindaporsius Год назад
Very nice how you show how to not mess with existing code-base.
@IAmTimCorey
@IAmTimCorey Год назад
Thanks!
@thepuddingclub5288
@thepuddingclub5288 2 года назад
Really great explanation. I now understand the concept much better 😊. Only thing that stands out in my view, is the line employees.Add(person.AccountProcessor.Create(person)). So person class injects itself as a parameter. This could be avoided if an abstract base class was used that had an applicant class passed as a parameter in the constructor.
@iT_dev41k
@iT_dev41k 4 года назад
Thank you very much, Tim. You explained SOLID pretty easy. I guess you've found the setting of interface\abstract autogeneration, but may be it will helpful for someone else:to avoid NotImplementedException for properties get;set; just go to Tools -> Options -> Text Editor -> C# -> Advanced -> Implement Interfaces or Abstract Class -> prefer auto properties. Thanks again!
@IAmTimCorey
@IAmTimCorey 4 года назад
You are welcome.
@paymannosrati6598
@paymannosrati6598 Год назад
Thank you so much Tim, that was helpful. like always.
@IAmTimCorey
@IAmTimCorey Год назад
You are welcome.
@HawkEyeExplorers
@HawkEyeExplorers 2 года назад
Great explanation. Thank you so much.
@IAmTimCorey
@IAmTimCorey 2 года назад
You are welcome.
@TheAngelOfDeath01
@TheAngelOfDeath01 6 лет назад
As always, an excellent video! In your comment to me on the previous video regarding SRP, you mentioned making a follow up video and combining all 5 patterns in SOLID. I think it would honestly be a very good idea, since there is a massive difference between seeing all the "players in action at the same time" and then seeing each of them separately -- kind of like an orchestra; music always sounds better when you have more than one instrument, you know? You sure do explain this a lot better than my old teachers did back in the day. I had hoped that you would have explained the concept of Abstract classes and how they also tie in with interface, but given the way you went about this video, I sure can understand why you didn't -- there is more than enough "meat" on this bone as it stands -- which is good, there is a lot to cover! Also, regarding namespaces, you forgot to mention that when you use namespaces, the final point of the namespace, eg. "OCPLibrary.Accounts", then you cannot have a class called "Accounts" as those things will create conflicts. :-)
@IAmTimCorey
@IAmTimCorey 6 лет назад
Yep, I think I'll start working on a full SOLID video. I think by the end, the videos will be mostly SOLID anyway but a good full example would probably be good. I'll probably do a separate video at some point on abstract classes.
@mizanrahman7287
@mizanrahman7287 2 года назад
Mesmerizing video. You have made my day.
@IAmTimCorey
@IAmTimCorey 2 года назад
I am glad it was so helpful.
@TuncTurel
@TuncTurel 2 года назад
Hi Tim, this specific example made things a bit muddy for me but I still liked the video because I believe I got the message you were trying to communicate through. A great example I came across of OCP is when we were working with certain libraries or assets and essentially in order to expand what the library offers we can simply use an interface they already used in advance. If I'm not mistaken we used this principal on a node based slide system that lets you add new slides without modifying the original library but simply using its ISlide interface. That way you have a new slide node you can employ in the graph as it easily fits the entire system and other slides are not affected since nothing core changes. If it ever comes to it I would love it if you showed us real life scenarios from work you do or you've done that use OCP. Thank you for the videos and greetings from the Netherlands!
@tomthelestaff-iamtimcorey7597
@tomthelestaff-iamtimcorey7597 2 года назад
Thanks for the great feedback
@ramernuneza4649
@ramernuneza4649 3 года назад
Great video Tim! 🙂
@IAmTimCorey
@IAmTimCorey 3 года назад
Thanks! 😀
@richi317
@richi317 4 года назад
Congratulations! Good explanation, very clear.
@IAmTimCorey
@IAmTimCorey 4 года назад
Thank you!
@ggunni
@ggunni 2 года назад
Learning SOLID, this helped a lot, thanks.
@IAmTimCorey
@IAmTimCorey 2 года назад
You are welcome.
@umbertech
@umbertech 2 года назад
beautiful explanation. Thanks!
@IAmTimCorey
@IAmTimCorey 2 года назад
You are welcome.
@tripore
@tripore 5 лет назад
Fantastic ! Thanks
@IAmTimCorey
@IAmTimCorey 5 лет назад
You are welcome.
@nathanunderbsd5972
@nathanunderbsd5972 5 лет назад
I am beginner on .NET which I just started December 2018 but it seems gradually change my style of learning process on how to do full stack .NET web/dev in standard and best practices, all videos are pointing to a very neat and precise coding style. Can't wait new videos from you. Maybe gang of four (GoF) principle? Which I just read 3 days ago.
@IAmTimCorey
@IAmTimCorey 5 лет назад
GoF is coming (at least some of them) in the future.
@harag9
@harag9 6 лет назад
Excellent video, thanks for explaining this, I was a little concerned with all the copy and paste of the same code, breaking the S in the series, but completely understand why in the lesson, normally as you said you would create a base class :)
@IAmTimCorey
@IAmTimCorey 6 лет назад
Yeah, possibly a base class or maybe just a single class with the code and then calls to it from the multiple locations. The tough thing is that a lot of the code changes.
@StephenOwen
@StephenOwen 4 года назад
Heads up: time stamp through @14:00 explains the problem Open/Closed is there to SOLVE. That segment highlights what you woudl do if we didn't have Open/closed principle, edit your classes all the time to add new features. From @16:00 and on, Tim shows how to implement OpenClosed. I recommend watching the first part as it's a great example of the anti-pattern.
@IAmTimCorey
@IAmTimCorey 4 года назад
Thanks for sharing.
@jphvnet
@jphvnet 3 года назад
Good videos! I need to write more code to get into problems which requires this decoupling
@IAmTimCorey
@IAmTimCorey 3 года назад
Thanks!
@alejandromachacanavia8036
@alejandromachacanavia8036 Год назад
Really good example!!!
@IAmTimCorey
@IAmTimCorey Год назад
Thanks!
@rennjaysoterio2543
@rennjaysoterio2543 4 года назад
Hi, Just want to commend your work. I've learned a lot from you.
@IAmTimCorey
@IAmTimCorey 4 года назад
Thank you!
@refaathussein482
@refaathussein482 5 лет назад
Many thanks Tim :)
@IAmTimCorey
@IAmTimCorey 5 лет назад
You are most welcome. Thanks for watching.
@juhairahamed5342
@juhairahamed5342 3 месяца назад
Good Explanation with real time
@IAmTimCorey
@IAmTimCorey 3 месяца назад
Thanks!
@FredIsThere
@FredIsThere 4 года назад
Quality content. Good tips.
@IAmTimCorey
@IAmTimCorey 4 года назад
Thank you.
@KiranYadavOG
@KiranYadavOG 9 месяцев назад
Thanks for this!
@IAmTimCorey
@IAmTimCorey 9 месяцев назад
You are welcome.
@boryskot762
@boryskot762 3 года назад
The best explanation ever
@IAmTimCorey
@IAmTimCorey 3 года назад
Thanks!
@nordinemokhtari3496
@nordinemokhtari3496 4 месяца назад
Thank you very much !! your example helped me solve a problem in real life
@IAmTimCorey
@IAmTimCorey 4 месяца назад
You are welcome.
@paulofernandoee
@paulofernandoee 2 года назад
Great video! To speed up things when implementing the interface, one could select the excerpt "=> throw new NotImplementedException()" and CTRL + H then ALT + A 😅
@tomthelestaff-iamtimcorey7597
@tomthelestaff-iamtimcorey7597 2 года назад
Thanks for theTIP!
@javadhashtroudian5740
@javadhashtroudian5740 2 года назад
I love your chanel. Anyway, for those who don't know, Acme produced the anumation cells and its use in the Road Runner was an in joke by the WB animators.
@IAmTimCorey
@IAmTimCorey 2 года назад
If it wasn't obvious, I was heavily influenced growing up by their fictional production of anvils, catapults, and coyote-carrying rockets. 😆 Thanks for sharing.
@kevamorim
@kevamorim 4 года назад
Nice video, thanks! I think that writing code with OCP in mind, helps a lot, since it makes code a lot better. But if you start from a project that is already in production and not developed thinking about OCP, it will be really hard to make changes without changing what is already working. But, even if its working, you have to change code when you want to refactor. And, Unit Tests should be here to help us not to introduce bugs on working code. The point is, I think we have to write code with this principle in mind, but don't overthink or overdo it. Thanks for the video, it helped me a lot to clear this concept! :)
@IAmTimCorey
@IAmTimCorey 4 года назад
Yep, that is very true. You have to be careful how you optimize your code. The key is to make things a little better than you found them.
@kevamorim
@kevamorim 4 года назад
@@IAmTimCorey Nice advise! :)
@jeffkennedy2269
@jeffkennedy2269 2 года назад
Great video!
@IAmTimCorey
@IAmTimCorey 2 года назад
Thanks!
@codeZarathustra
@codeZarathustra 2 года назад
Good explications, thank very much.
@IAmTimCorey
@IAmTimCorey 2 года назад
You are welcome!
@stephenyork7318
@stephenyork7318 4 года назад
At 32:00 you could use “composition” and have ManagerAccounts take an Accounts class in its ctor which calls create. Could also be seen as a decorator.
@IAmTimCorey
@IAmTimCorey 4 года назад
There are usually different ways to tackle problems in development. This way demonstrated the topic best.
@krystian8250
@krystian8250 4 месяца назад
Thank you! Good explanation :)
@IAmTimCorey
@IAmTimCorey 4 месяца назад
You are welcome.
@michaeladams932
@michaeladams932 3 года назад
The video is published more than 2 years ago, but Tim still keeps replying to comments.
@IAmTimCorey
@IAmTimCorey 3 года назад
I like to know the videos are still adding value! Thanks for watching.
@michaeladams932
@michaeladams932 3 года назад
@@IAmTimCorey Created a repository following your tutorials. Open to pull-requests. Gonna finish in a week. github.com/Muhammadrasul446/SOLID_C-Sharp
@joemarkarnaiz8441
@joemarkarnaiz8441 3 года назад
That's why I love Tim!!
@BunmJyo
@BunmJyo Год назад
​@@IAmTimCoreythanks for teaching 👍🎉
@kylegivler8372
@kylegivler8372 3 года назад
You are a hero :D
@tomthelestaff-iamtimcorey7597
@tomthelestaff-iamtimcorey7597 3 года назад
Thanks for watching!
@suhasparameshwara8447
@suhasparameshwara8447 3 года назад
Awesome Tutorial
@IAmTimCorey
@IAmTimCorey 3 года назад
Thanks!
@lupf5689
@lupf5689 Год назад
Hi Tim, this is your customer. Thanks for providing the new software version, it's great! Anyway, we just now realized that humans can have middle names! Could you please add middle name support by tomorrow morning? I know it's a tough deadline, but since we spent the whole last year refactoring everything to be SOLID, I'd assume such changes can be done much quicker now and there are fewer places to touch, so less stuff can break. Thx and keep up the great work! ;-)
@IAmTimCorey
@IAmTimCorey Год назад
That sounds about right. Good designs don't make up for poor planning.
@hardgrafter2787
@hardgrafter2787 5 лет назад
Very good. With regards to keeping your interfaces alongside your concrete classes. Once you are writing a large Prism or similar 'modular' application I have learnt that is not best practice to do this. Normally we will put interfaces in a separate 'Infrastructure' project. This way once you are leveraging dependency injection & using an IOC container to inject dependencies you do not have modules being dependent on other modules, rather modules that need to resolve those types can reference the 'infrastructure' interface module and the concrete types are then resolved at run time. This way a module can be used by another application and achieves real separation of concerns. Obviously this is out of the scope of this small example application...
@IAmTimCorey
@IAmTimCorey 5 лет назад
Yep, it does depend on how you intend to use them later on, good point.
@pedroreisbr
@pedroreisbr 3 года назад
The best explanation on RU-vid!
@IAmTimCorey
@IAmTimCorey 3 года назад
Thanks!
@maleta666
@maleta666 5 лет назад
Thanks Tim
@IAmTimCorey
@IAmTimCorey 5 лет назад
You are welcome.
@nguyenkhoa1700
@nguyenkhoa1700 3 года назад
Thank you!!!
@IAmTimCorey
@IAmTimCorey 3 года назад
You're welcome!
@nick8teen
@nick8teen 2 года назад
This clarification really saved the day for me, Mr. Corey! I still learn, but feel like understanding quite well a lot more thanks to Your videos. Just to note: I think that it makes sense to use enum with flags in EmployeeModel class instead of those boolean properties like isExec, isManager etc. Is that a fine sollution?
@CyberAbyss007
@CyberAbyss007 4 года назад
Thank you!
@IAmTimCorey
@IAmTimCorey 4 года назад
You are welcome.
@jameshan4026
@jameshan4026 4 года назад
great video and the comments are also helpful.
@IAmTimCorey
@IAmTimCorey 4 года назад
Thank you!
@sainathkesavan4559
@sainathkesavan4559 2 года назад
Thanks!
@IAmTimCorey
@IAmTimCorey 2 года назад
Thank you!
@lukenukem8028
@lukenukem8028 4 года назад
[48:03] I'm quite glad you actually mentioned using base classes, since it's how I create quite flexible, extensive things. I was honestly starting to think you were just all about turning everything into interfaces. That's no better than turning everything in C++ into templates. LoL
@IAmTimCorey
@IAmTimCorey 4 года назад
Yep, just be careful not to use abstract classes to do too much.
@lukenukem8028
@lukenukem8028 4 года назад
Oh yeah, abstract classes can run code. Actually, that is handy.
@rennyschweiger
@rennyschweiger 5 лет назад
Hi Tim, I'm working through your C# App From Start To Finish, and digesting some of these other videos, and this is all great stuff; thanks for this. I'm a long-time VB hobbyist (I can't say I'm a pro developer even though I have quite a bit of code here and there in macros and smallish apps at work) and I'm trying to transition to C# and to think more in OOP. I'm struggling with Interfaces (saw your Interfaces vid) and this compartmentalization of the code. (I come from a world where *everything* was in the frmMain module... ;-) In this particular video, I would have approached it as using an Employee object, and used an employee.ActivateAccount(applicant, empType) method, where the empType is an enum. Then, instead of adding an entire set of interfaces and models for a different type of employee, you just add a new entry to the EmployeeType enum, and add a new entry to your case or switch block to implement differently where necessary. You're not necessarily changing code flow nor are you touching existing logic, but you are adding sections in a somewhat safe manner. I get that this is just a simple example, but if you have to recover from not allowing for different employee types (i.e., a big requirements hole) you're gonna have to tear into some code anyway. Also, while I understand that you should have different classes to represent your various objects, to have different classes to do different *things* seems strange to me -- wouldn't you just implement different methods or properties for the class? I have a nagging feeling that I'm missing some higher level understanding or approach; perhaps you need a few PowerPoint slides after all... Keep up this great work. I was floundering until I discovered you. Regards, Renny
@IAmTimCorey
@IAmTimCorey 5 лет назад
The issue with the enum is that you are making changes in multiple places then. Yes, it is only adding logic not altering it (for the most part) but it is a change. Besides, if you make that change and the new part of the enum has a problem, you break existing code. One of the things that will help is practice. The more you see these situations, the more you will understand the long-term implications. This is a rather hard one to jump into when transitioning over to a true OOP way of thinking. Great thoughts though. I'm glad you are thinking it through.
@andrewjakobs528
@andrewjakobs528 4 года назад
Thanx for the excellent explanation. Even though the changes ofcourse are still perceptible to bugs as you had to rewrite everything to interfaces, and then did not change the original names of the 'base' classes which might make it easy to mistake (like PersonModel should have be renamed to StaffModel and the Accounts to StaffAccounts because otherwise in the future it could be mistaken for anything else). Also it's easy to say, now you are confident to add a new employeeType.. But to be honest, if the original Accounts was implemented with the switch, I also would be confident to if I had to make a change, as it wouldn't really matter if I had to create the original PersonModel with EmployeeType set, or if I had to set a new Model. The problem now is that if there is one slight change to the 'PersonModel' you have to change ALL your other classes too instead of just 2 classes (PersonModel/Accounts), so it might introduce some more bugs.. So yeah, it solves one problem, but it also creates another which you wouldn't have with the first way of implementing multiple employeetypes.. But maybe it's just me that IS confident in making changes to things like switches etc. and wanting to actually see what happens in different cases at that point (for instance the differences between emailaddress creation). Also if this was a big application, it would have been hell if you went from everything in one folder with the OCPLibrary namespace to separate folders and NOT have it have OCPLibarary. namespace and then later have some folders to have it as a namespace. That would make it really confusing, and in the end, changing namespaces of the library after it is in production you get the problem of the other projects might have to be rebuild again and having problems with the namespaces. Also in this case you called the folder Accounts, but we did have a class named Accounts and it created problems with the TechnicianAccounts class which was created in the Accounts folder, and that made the original Accounts class get a problem with having the same namespace as the original Accounts class wasn't in the Accounts namespace. If the Accounts class would have been names StaffAccounts it wouldn't have this problem BUT you would have problems of some ...Accounts classes be part of the OCPLibrary namespace and some of the OCPLibrary.Accounts namespace which ofcourse is very confusing. (Just like my text here, LOL). So in the end, you always have to be careful if you change code/namespaces after it's already in production, no matter which principle you use.
@IAmTimCorey
@IAmTimCorey 4 года назад
Yep, every situation will be different but the best thing is if you architect your application with OCP to begin with (as much as it makes sense) rather than trying to change it after the fact.
@ejazahmad2636
@ejazahmad2636 3 года назад
Great explanation
@IAmTimCorey
@IAmTimCorey 3 года назад
Thanks!
@vladsoloduha1655
@vladsoloduha1655 4 года назад
During your lessons i improve not only programming skills, but english skills too)
@IAmTimCorey
@IAmTimCorey 4 года назад
Great!
Далее
Why Use Design Patterns When Python Has Functions?
23:23
How Senior Programmers ACTUALLY Write Code
13:37
Просмотров 1,4 млн