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.
@IAmTimCorey2 жыл бұрын
Excellent! Best wishes on the interview.
@markdee35062 жыл бұрын
How did the interview go?
@samuelpage5409 Жыл бұрын
One thing I really appreciate about your videos is that you speak clearly enough for KZbin's auto-generated captions to work accurately. Great information, thank you for the video!
@IAmTimCorey Жыл бұрын
You are welcome.
@wisbenah6 жыл бұрын
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!
@IAmTimCorey6 жыл бұрын
I appreciate the kind words. I'm glad you appreciate my approach.
@nathanunderbsd59725 жыл бұрын
This is not only MVP, I make it higher than MVP.
@GuySymonds14 жыл бұрын
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.
@IAmTimCorey4 жыл бұрын
I am glad you enjoyed it.
@electrocatalyst Жыл бұрын
Thanks for explaining this principle. All the other videos which try to explain it in 3 minutes fail to explain it completely.
@IAmTimCorey Жыл бұрын
You are welcome.
@rubyelephant592210 ай бұрын
Excellent work, neatly and concisely explained I wish my University had a teacher like you
@IAmTimCorey10 ай бұрын
I am glad it was helpful.
@DepressionAlgorithm6 жыл бұрын
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!
@IAmTimCorey6 жыл бұрын
You are welcome.
@pedroluiz80193 жыл бұрын
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-iamtimcorey75973 жыл бұрын
Tim has real world experience and thinks its important to share it. Viewers seem to agree.
@franciscooliveira858511 ай бұрын
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!
@IAmTimCorey11 ай бұрын
I am glad it was helpful.
@shawnmofid71315 жыл бұрын
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.
@IAmTimCorey5 жыл бұрын
I appreciate the kind words.
@brianyoung38765 жыл бұрын
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!
@IAmTimCorey5 жыл бұрын
Yep, that is fairly common. I'm glad these will be useful to you.
@chrisrey25164 жыл бұрын
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
@IAmTimCorey4 жыл бұрын
Great to hear!
@ajitsaharan94454 жыл бұрын
I have no word....its awesome, your tutorials changed my coding style.....Thank you Sir...Super Love for You
@IAmTimCorey4 жыл бұрын
I am so glad they were helpful.
@nikinikolov65705 жыл бұрын
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.
@IAmTimCorey5 жыл бұрын
You are most welcome. Thanks for watching.
@stevencruz9783 жыл бұрын
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.
@IAmTimCorey3 жыл бұрын
Excellent!
@StephenOwen4 жыл бұрын
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.
@IAmTimCorey4 жыл бұрын
Thanks for sharing.
@TuncTurel2 жыл бұрын
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-iamtimcorey75972 жыл бұрын
Thanks for the great feedback
@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 :)
@eliedh82715 жыл бұрын
you really do clear up the confusion and the frustration around learning c#. xD
@IAmTimCorey5 жыл бұрын
Awesome! That's the goal. I'm glad you feel like I am accomplishing it.
@mindaugasanuzis980221 күн бұрын
You're the best teacher. Period.
@IAmTimCorey21 күн бұрын
Thank you!
@soubarnobanerjee82572 жыл бұрын
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
@IAmTimCorey2 жыл бұрын
I am glad it is clear now.
@luismendez94364 жыл бұрын
Agree with previous comments...exactly what the type of tutorials one needs. Thanks for this.
@IAmTimCorey4 жыл бұрын
Glad it was helpful!
@iT_dev41k4 жыл бұрын
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!
@IAmTimCorey4 жыл бұрын
You are welcome.
@TundeAjao6 жыл бұрын
Great Tim .... you are doing a great job in making C# easier for people
@IAmTimCorey6 жыл бұрын
Thanks!
@tchpowdog4 жыл бұрын
I understand this is just a simple example to convey the principle, but I have two main issues with abiding to this principle for EVERYTHING: 1. In the real world, your IApplicantModel interface would represent some input for an Employees data table, so if you add a field to the Employees table, you now have to go through all of your Applicant models and add this new member, plus go through all the ApplicantAccounts and add the new logic for this new member and to me, that's defeating the purpose. 2. It creates file hell I use interfaces for all of my service methods, repository methods, and application models (NOT data entity models, those should be hard-bound imo). I ONLY use interfaces as a precaution and I even put my interfaces inside of my class files (at the top before the class declaration). I use interfaces just in case one day a change or addition shall warrant using the interface as shown here (but there has to be good reason for me, it has to warrant itself), in that case I take the interface out of my class file and put it into a file of it's own, then mass update reference. This may not be a "good" way but I've found it works best for me and that's what I love about programming. I love your videos, Tim . Cheers!
@IAmTimCorey4 жыл бұрын
I definitely don't recommend applying OCP to everything. Software development is definitely about being knowledgeable about best practices while applying what works best for your project.
@tonybapuji59562 жыл бұрын
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.
@IAmTimCorey2 жыл бұрын
You are most welcome. Thanks for watching.
@noextrasugar Жыл бұрын
Great teaching style Tim, so glad I've found this channel!💛💪
@IAmTimCorey Жыл бұрын
Awesome, thank you!
@NickSteffen Жыл бұрын
I once came across a library that was zealously implementing open/closed. Each object had suffix number (some were on their 30th version). Each of these suffixed versions depended various suffixed versions from other objects. It instantly struck as the closest I’ve seen code come to being actual spaghetti. The documentation was 90% “object9 is deprecated”, please use object10. Then object10s documentation was “object10 is deprecated, please use object11”. In short you have to remember that open/close was created quite a long time ago. (Along with the rest of solid). If there is any principle you might disregard completely it’s this one. Make good automated testing instead.
@IAmTimCorey Жыл бұрын
Overuse of any principle is a bad thing.
@hugogogo13 Жыл бұрын
Tim is polite in his answer but anyone would tell you that if you think having Object1 & Object2 is OCP, then you should probably watch this video again. Closed to modification does not mean it's impossible to make a change/fix. Object2 should have never existed in the first place. Instead, OCP is an 'encapsulation & polymorphism combined principle' that let you use objects through functionalities rather than definitions by associating them via what they are capable of.
@NickSteffen Жыл бұрын
@@hugogogo13 Sounds nice in theory, only the original definition according to Meyer is exactly how I described. Instead of modifying object 1 you extend it by creating object 2. Very few examples consider what happens when you have more modifications to make and have to create object 3. Even the modern interpretation using an abstract base or interface and then replacing the implementation with a new one instead of inheriting the previous object is a maintenance nightmare. You seem to have compiled your own version of the principle that makes it valid. but if you go and read the actual definitions of it online it is mostly as I’ve said. I would almost argue that the principle as you describe is entirely different and probably deserves a different name.
@hugogogo13 Жыл бұрын
@@NickSteffen fair enough. That's okay then, SLID is still a catchy name 😉
@bharathyadav36146 жыл бұрын
Ever since I started following you on KZbin, 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!
@IAmTimCorey6 жыл бұрын
Awesome! I'm glad you're enjoying the series.
@vinuhosanagar16 жыл бұрын
Hi Bharath, I'm also WPF developer. Which company you work for?. I stay in Bangalore. Can we connect on vinaypalaksha1@gmail.com
@alebado86645 жыл бұрын
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!
@IAmTimCorey5 жыл бұрын
I appreciate the kind words.
@dvalmont075 жыл бұрын
Thank you for share your wisdom. This isn't an easy concept, but your class was crystal clear. Love from Brazil!
@IAmTimCorey5 жыл бұрын
You are most welcome. Thanks for watching.
@pawanshetty47953 жыл бұрын
Awesome approach of explanation - step by step and reasons presented why not to follow a specific approach.
@IAmTimCorey3 жыл бұрын
Glad it was helpful!
@davidmipancito5 жыл бұрын
Practice! Practice! Practice its going to be my goal to be better programming, Thnks a lot Tim for this great video tutorial!
@IAmTimCorey5 жыл бұрын
Yep, practice is really important. Glad you enjoyed the video.
@ultroai3 жыл бұрын
Great and simple explanation of rather hard to get principle. Thanks for it.
@TheAngelOfDeath016 жыл бұрын
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. :-)
@IAmTimCorey6 жыл бұрын
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.
@p199a6 жыл бұрын
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.
@IAmTimCorey6 жыл бұрын
Excellent!
@Muuuzzzi5 жыл бұрын
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!
@IAmTimCorey5 жыл бұрын
I am glad you are enjoying the content and my style.
@hardgrafter27875 жыл бұрын
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...
@IAmTimCorey5 жыл бұрын
Yep, it does depend on how you intend to use them later on, good point.
@fadidib85162 жыл бұрын
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.
@IAmTimCorey2 жыл бұрын
Excellent!
@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 Жыл бұрын
That sounds about right. Good designs don't make up for poor planning.
@pedroreisbr3 жыл бұрын
The best explanation on KZbin!
@IAmTimCorey3 жыл бұрын
Thanks!
@iam_Raavanan3 жыл бұрын
Wowwww!!! What an amazing explanation. Highlight is practical examples, which makes this sooooooo goooooood!!!!
@IAmTimCorey3 жыл бұрын
Glad it was helpful!
@iam_Raavanan3 жыл бұрын
@@IAmTimCorey Is there any possibility for doing videos in C++. It would be really helpful. Consider it as request.
@soucianceeqdamrashti81755 жыл бұрын
Really good and well explained with the code. Excellent work! Loving the series.
@IAmTimCorey5 жыл бұрын
Thank you!
@Cmppayne265426 жыл бұрын
You can tell Visual Studio to not throw on implementing properties on interfaces in Tools -> Options -> Text Editor -> C# -> Advanced -> When Generating Properties -> prefer auto properties. Not really sure why they don't enable this by default honestly.
@IAmTimCorey6 жыл бұрын
Wow, that's awesome! Thanks for pointing that out. I agree it should be enabled by default. I'll have to mention that to some people to see if they are willing to change the default.
@pawesajnog24315 жыл бұрын
Hehe i wrote this same. You are first.
@lukenukem80284 жыл бұрын
[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
@IAmTimCorey4 жыл бұрын
Yep, just be careful not to use abstract classes to do too much.
@lukenukem80284 жыл бұрын
Oh yeah, abstract classes can run code. Actually, that is handy.
@longuinni6 жыл бұрын
Great video Tim. Easy to understand, good examples... Thanks for sharing that knowledge!!
@IAmTimCorey6 жыл бұрын
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.
@dowdag6 жыл бұрын
Great video - you got through the video with out mentioning polymorphic once :)
@IAmTimCorey6 жыл бұрын
I try to avoid confusing words that don't add to the discussion.
@andrewjakobs5284 жыл бұрын
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.
@IAmTimCorey4 жыл бұрын
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.
@michaeladams9323 жыл бұрын
The video is published more than 2 years ago, but Tim still keeps replying to comments.
@IAmTimCorey3 жыл бұрын
I like to know the videos are still adding value! Thanks for watching.
@michaeladams9323 жыл бұрын
@@IAmTimCorey Created a repository following your tutorials. Open to pull-requests. Gonna finish in a week. github.com/Muhammadrasul446/SOLID_C-Sharp
@joemarkarnaiz84413 жыл бұрын
That's why I love Tim!!
@BunmJyo Жыл бұрын
@@IAmTimCoreythanks for teaching 👍🎉
@markyap47554 жыл бұрын
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.
@IAmTimCorey4 жыл бұрын
I am glad they are so helpful.
@thepuddingclub52882 жыл бұрын
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.
@StephenOwen4 жыл бұрын
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!
@IAmTimCorey4 жыл бұрын
Glad it was clear.
@lindaporsius Жыл бұрын
Very nice how you show how to not mess with existing code-base.
@IAmTimCorey Жыл бұрын
Thanks!
@RiderInHell4 жыл бұрын
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
@IAmTimCorey4 жыл бұрын
Glad it was helpful!
@kaushiks8126 жыл бұрын
U r d best .when it comes to teaching .Please 1 video on SQL performance tuning and mvc request life cycle
@IAmTimCorey6 жыл бұрын
I will make sure those topics are on the list. Thanks for the suggestions.
@sagarviradiya4 жыл бұрын
@@IAmTimCorey are these videos prepared, i would love to watch that.
@paulofernandoee2 жыл бұрын
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-iamtimcorey75972 жыл бұрын
Thanks for theTIP!
@eyebee-sea44445 жыл бұрын
Great lecture Tim! But there is one thing I don't like in this solution, and that's the property AccountProcessor. Its initialization violates LSP, and its sheer existence SRP. Sure, there is an extra implementation for any account type, but it's not the purpose of an applicant to provide any mapping functionality for translating his properties to the EmployeeModel or any other type.
@IAmTimCorey5 жыл бұрын
I don't really agree on the violations. Part of it comes down to the definition of what a responsibility is but we can apply LSP.
@eyebee-sea44445 жыл бұрын
@@IAmTimCorey sorry, meant DIP, not LSP.
@amdretm2 жыл бұрын
I love your videos! I have a quick question: I have bingewatched your SOLID series for a second time to refresh it in my memory, and I can't help but notice that almost all of them favor the use of interfaces. However, I can't help but think that these interfaces implemented without an abstract BaseClass are always violating DRY. For example, here the applicants share some similar lines. It's not that big of a problem here, but in another video (I think it was ISP, with the DVD and Audiobook examples), the modules were sharing the same method but each implementing it on their own with the exact same lines. I just find it awkward to use interfaces because they seem to regularly create moments where you accidentally repeat yourself.
@IAmTimCorey2 жыл бұрын
DRY isn't about not having any repetition. It is about not having the same exact logic more than once. The methods may have the same signature, but they may do different things. They may even do the same thing, but in a way that is not guaranteed to stay the same forever. In those cases, they aren't violating DRY. If you found that you did have exact repetition, you don't need to use a base class (inheritance isn't about code sharing, it is about a relationship - if there isn't a strong relationship, you shouldn't use inheritance). Instead, just create a class with a method that both locations can call. Interfaces are the primary OOP system used in modern development. They give you flexibility, testability, and more.
@amdretm2 жыл бұрын
@@IAmTimCorey Thank you for your thorough explanation, that makes a lot of sense, especially the part about relationship/code sharing, gives me a lot of food for thought. I appreciate you took the time!
@solomonbarayev4200 Жыл бұрын
Very well explained. I was wondering the same thing..
@movsar423 жыл бұрын
Isn't that illogical to put AccountsProcessor inside of person model? I mean, I don't process corporate changes if I am accepted to a company, rather it's done by some external processor upon my person... I feel like these patterns sometimes confuse and mess things up more than provide help.
@genesessilva34293 жыл бұрын
I get what you're thinking. You're viewing things through a "logical" scope. The point is that every user has a own account management and not that they make their stuff by themselves.
@davidsuarez53174 жыл бұрын
HUGE EXPLANETION!! Like a lot your videos. Greetings from Cuba
@IAmTimCorey4 жыл бұрын
Thanks!
@ryanfreeman6632 жыл бұрын
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.
@IAmTimCorey2 жыл бұрын
Glad it was helpful!
@IDontWannaSayMyName19954 жыл бұрын
So with these SOLID principles, are you supposed to use all of them all the time, or pick and choose from them depending on the situation?
@IAmTimCorey4 жыл бұрын
Pick and choose. In general, they will almost always apply but they may not always be helpful. You choose what is best for your application. Good question.
@JottaaHD Жыл бұрын
Hey Tim, I've been watching your SOLID videos and really enjoying them but I have one question. With the way we're structuring our classes, creating interfaces and dealing with inheritance, how would these same classes be stored in a database? Would a table for each be correct? What if I want to retrieve all Persons in my database, then they would be scattered in different tables. Would we have to define specific database Entities that map our Models and define database relationships through our ORM to get the database structure we want? I'm used to have more simple models which are easily mapped to a single entity and its respective repository, that's why I'm asking would would be correct to do in the scenarios described in the video :) Thanks in advance!
@kevamorim4 жыл бұрын
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! :)
@IAmTimCorey4 жыл бұрын
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.
@kevamorim4 жыл бұрын
@@IAmTimCorey Nice advise! :)
@harag96 жыл бұрын
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 :)
@IAmTimCorey6 жыл бұрын
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.
@codykuch52932 ай бұрын
Great explanation, really hit home on why extension is the way to go and why modification is so dangerous. Which is why I think you overlooked the concept of a base class and hierarchy a little too quickly. That’s exactly what child classes inheriting a base class are doing: extending. You were talking about violating DRY; a base class can do everything an interface could with the benefit of reusing code. If you need more logic in a particular function for a child class, then you create a new function with a call the base class function. And if base function(s) shouldn’t be reused on that child class, maybe you shouldn’t be extending off of that base class…? Interfaces are great for unit testing and guardrails, but anything else can be done with hierarchies. Yes you need to be careful (calling a base function from a child class when you meant to call the child function…yikes) but it’s a powerful tool.
@IAmTimCorey2 ай бұрын
Inheritance is a powerful tool, but it is also very limited. You need to be careful when you use it that you don't cause more problems than you started with. For instance, if you decide to improve a method, so you create a child class, everything seems good. But then what if you wanted to change a different method but use the original of the first method? Now you have two different children inheriting from the same base. That seems fine. But now what if you want both of the updated methods? Now you have a problem. You cannot inherit from either child class without duplicating the work of the other. Inheritance locks you in a lot more than you really want if you aren't really, really careful.
@codykuch52932 ай бұрын
@@IAmTimCoreyyou’re correct of course, and careful designing and sticking to lose coupling-tight cohesion is a requirement for sure. But for that particular example one could argue the same implementation done with interfaces would also require duplicated code. In my opinion, you’ll have to violate DRY in the real world regardless. I think hierarchies do it far less, but you can get tighter coupling as your example illustrates.
@nathanunderbsd59725 жыл бұрын
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.
@IAmTimCorey5 жыл бұрын
GoF is coming (at least some of them) in the future.
@stephenyork73184 жыл бұрын
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.
@IAmTimCorey4 жыл бұрын
There are usually different ways to tackle problems in development. This way demonstrated the topic best.
@javadhashtroudian57402 жыл бұрын
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.
@IAmTimCorey2 жыл бұрын
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.
@AnalogGame3 жыл бұрын
I really like the clear explanation and the examples used. Have a better understanding of open Closed Principle
@IAmTimCorey3 жыл бұрын
Glad it helps.
@ankuronlyu Жыл бұрын
In my project we are not following OCP principle properly , we are keeping modifying exiting class and functions. Thanks for this nice video
@IAmTimCorey Жыл бұрын
You are welcome.
@ksenthil205 жыл бұрын
Tim, Thank you for making this video. Very clear explanation with examples.
@IAmTimCorey5 жыл бұрын
You are most welcome. Thanks for watching.
@jagjotjaggi5 жыл бұрын
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!!!!!
@IAmTimCorey5 жыл бұрын
I appreciate the kind words. I'm glad you are enjoying my content.
@fairozahmed68885 жыл бұрын
A big thank you for your awesome tutorials. God bless you. Love and Respect from India.
@IAmTimCorey5 жыл бұрын
You are most welcome.
@bsouzafilipe3 жыл бұрын
You made a helpful explanation. Thank you, it was easier to understand.
@tomthelestaff-iamtimcorey75973 жыл бұрын
Glad you found it helpful. Thanks for sharing.
@1011141046 жыл бұрын
Great instruction. Excellent, practical but not incomprehensible example app/code! Thanks!
@IAmTimCorey6 жыл бұрын
I am glad you found it useful.
@absl85683 жыл бұрын
15:40 think i will record part Tim saying "oook" and play it, each time i get new task at work haha
@IAmTimCorey3 жыл бұрын
LoL - The boss may not see the humor
@FXK234 жыл бұрын
Bravo, composition over inheritance and use of the strategy pattern ;)
@IAmTimCorey4 жыл бұрын
Thank you!
@Layarion4 жыл бұрын
what is composition?
@FXK234 жыл бұрын
@@Layarion Instead of inherit from a class for the use of certain base functionality. Put that Base functionality in another class and inject it in your constructor) from yout class and assign the instance to a private readonly field. You can now use the desired functionality by composition (private field with necessary class/functions) instead that you use the functionality because you're in a inheritance tree. Injection and private fields as Interface types of the desired class for loose coupling, i.e. you can change which implementation of the class you will inject to have as composite.
Hhhm, interesting point but for me that’s only really an argument when your faced with multiple inheritance scenarios (I do appreciate interfaces are preferred to inheritance for OCP and this is a demo so I am being "discussioney" rather than judgy). A Manager really "is a" Employee, and an Executive "is a" Manager. You really shouldn’t be copy/pasting FirstName/LastName around IMO. Okay, if you are then faced with a new requirement of Salesman (still okay) then a SalesManager (yeesh, possible multiple inheritance) then stuff breaks but, within reason, you shouldn’t design in requirements you don’t have. [digressing now but..] 20 years ago we used to spend weeks or even months meeting around whiteboards designing in what-ifs, only to find not only where they never asked for, 60% of the features they did ask for were never used! Refactoring tools are so quick and powerful now it’s just way better spending that time writing tests instead so you can safely refactor in change rather than spend that time trying to predict future change.
@juhairahamed53425 ай бұрын
Good Explanation with real time
@IAmTimCorey5 ай бұрын
Thanks!
6 жыл бұрын
Thanks Tim! This video I liked a lot and I learned a lot from it.
@IAmTimCorey6 жыл бұрын
Awesome! I love it when people learn something from my videos.
@mizanrahman72872 жыл бұрын
Mesmerizing video. You have made my day.
@IAmTimCorey2 жыл бұрын
I am glad it was so helpful.
@RalfsBalodis4 жыл бұрын
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 🤯
@IAmTimCorey4 жыл бұрын
Thanks Again. I'm adding all these to the videos.
@vladsoloduha16554 жыл бұрын
During your lessons i improve not only programming skills, but english skills too)
@IAmTimCorey4 жыл бұрын
Great!
@rennjaysoterio25434 жыл бұрын
Hi, Just want to commend your work. I've learned a lot from you.
@IAmTimCorey4 жыл бұрын
Thank you!
@abduljameel12012 жыл бұрын
Please create video on design smells and suggested refactoring for each smell
@IAmTimCorey2 жыл бұрын
Thanks for the suggestion. Please add it to the list on the suggestion site so others can vote on it as well: suggestions.iamtimcorey.com/
@nicollenemashego41314 жыл бұрын
Can you please make an example of a code that implements all the principles at the same time
@brendonanderson86734 жыл бұрын
I would love that too!
@IAmTimCorey4 жыл бұрын
Noted and added to the list
@stevedecker45104 жыл бұрын
Wish you had kept with the same project as your SRP explanation! I want to see you turn spaghetti code into a SOLID project! Thanks!
@IAmTimCorey4 жыл бұрын
I tried to keep things as clear as possible for each lesson. I agree it would be cool to do though. Maybe for an "Applying SOLID" course.
@stevedecker45104 жыл бұрын
@@IAmTimCorey In my opinion, it would be clearer if you used the same project since I already know what's in it and I wouldn't have to learn about the new project and try to imagine how you would implement all the SOLID principles into ONE project! This has been then problem for me. I can't find anyone using the one project thru all the SOLID principles and how the end should look like but instead, I'm given bits and peaces of it and then left to my own imagination to try and implement them all in one project. Problem is, I don't know if I did it right without having a few examples of the completed code in SOLID form!
@Neran2802 жыл бұрын
I do not clearly understand whats the point of the EmployeeModel class or did i miss some explanation? To me it looks like it is only used to compare all the different IApplicant models. The EmployeeModel must contain the union of all attributes of the different types (namely isManager, isExecutive, firstName, ...) while the models only differ in their AccountProcessor attribute and do not contain any data except what is common among them (names). The accountprocessor just tells you how to create a common "base class" namely the EmployeeModel out of this type by using an additional indirection. Im not entirely sure but cant this approach be simplyfied by using an abstract base class instead of having the EmployeeModel as a separate class, let the different types of employees inherit from it and put the Create() codes into the constructors? You also wont need to change the child classes if you add executive or manager to the base class as these default to false just like in EmployeeModel. However both approaches do have problems in common: If we created the executive first and then the manager, we would have had to change the executive because bool does not default to true. Also Main and EmployeeModel have to always change if we add a new type of person that comes with a new attribute.
@chriscatignani82063 жыл бұрын
Really great series..."As always"...I come away learning something new.
@IAmTimCorey3 жыл бұрын
Glad to hear it!
@HanselGraciadelBusto3 жыл бұрын
Simple, clear and useful, as usual. Thanks!
@IAmTimCorey3 жыл бұрын
You're welcome!
@kylegivler83723 жыл бұрын
You are a hero :D
@tomthelestaff-iamtimcorey75973 жыл бұрын
Thanks for watching!
@codeklaudia96963 жыл бұрын
22:15 An interface will allow us to add on to this with other classes. Inside PersonModel, extract interface. IApplicantModel. I believe this interface was created so that we would not modify Personmodel directly and violate the OCP principle
@kunik59354 жыл бұрын
Hi Tim. I have a question about the S, not about the O in SOLID (sorry :D but you mentioned it here and it brings me to think about one thing). As you said - "SRP - Classes should have only one reason to change". Ok. When we change the way we create an account for a person it is just one reason. But what if we have other methods, e.g. Edit(), Delete() and many others. Then the account class has more reasons to change. When we change the way we Edit account, Delete account, etc. How does it refer to SRP? P.S. I want to thank you for your videos. You really pushed my learning C# forward :)
@IAmTimCorey4 жыл бұрын
That does depend a bit on your interpretation of "reason for change". In order to not go crazy, I tend to think of methods as "one focused reason" and classes as "one general reason" to change. For instance, Person would not need to change generally unless how a person worked changed. Edit would not need to change unless the specific logic was altered.
@kunik59354 жыл бұрын
@@IAmTimCorey I was thinking if SRP could be related to methods in classes, not just to classes. Thanks for your answer, it lightened my mind 🙂
@gorkembykl70102 жыл бұрын
I just realised that I never subcribed... I am sorry Tim!! Done!
@IAmTimCorey2 жыл бұрын
Thanks!
@88spaces2 жыл бұрын
There are some semantic changes that you could make to improve the code. But that's not the point. The point is to demonstrate how to add functionality with minimal changes to existing code and this is a very good example.
@IAmTimCorey2 жыл бұрын
Thank you!
@harshpatel-wr1jl2 жыл бұрын
again great video TimCorey
@IAmTimCorey2 жыл бұрын
You are welcome.
@nordinemokhtari34965 ай бұрын
Thank you very much !! your example helped me solve a problem in real life
@IAmTimCorey5 ай бұрын
You are welcome.
@kk-jm2js3 жыл бұрын
I come from Java world and I was always curious that, in C# why we like to name classes as XXXModel? What exactly a model class means? Is it a pure data class with getters and setters?
@IAmTimCorey3 жыл бұрын
Yes, that is typically the meaning. A model is a class whose primary purpose is holding data.
@droam1293 жыл бұрын
It almost feels like the open/closed principle is backwards from this example... the example feels like “open for modification (eg we could modify the original Accounts class to fix a bug or change our business logic for how a PersonModel is created) but closed for extension (we never ADD new behaviors or responsibilities to the original Accounts class, but instead create new implementations). Am I looking at something the wrong way?
@IAmTimCorey3 жыл бұрын
We would not change the original class (except if it was buggy). We would extend it to add new functionality. You are looking at that as a "new implementation" but that new implementation builds upon the original, which is the point of OCP.