No video

Design Patterns: Liskov Substitution Principle Explained Practically in C# (The L in SOLID)

  Рет қаралды 188,569

IAmTimCorey

IAmTimCorey

Күн бұрын

Пікірлер: 497
@ethanvenencia5653
@ethanvenencia5653 3 жыл бұрын
3 years old but still quality content. Cheers man!
@IAmTimCorey
@IAmTimCorey 3 жыл бұрын
Thanks!
@alexstankovic2947
@alexstankovic2947 Жыл бұрын
This is timeless ❤
@RalfsBalodis
@RalfsBalodis 4 жыл бұрын
0:00 - Intro 1:32 - Demo code overview 3:04 - Liskov Substitution Principle: LSP Explained... 6:15 - Side note: Covariance and Contravariance, Preconditions Postconditions 10:17 - ...LSP Explained 13:58 - Considering the Open and close principle 17:24 - Implementing LSP: Refactoring demo code 29:23 - Note on abstraction in base classes 33:02 - Flexibility with LSP and Concluding remarks
@IAmTimCorey
@IAmTimCorey 4 жыл бұрын
As always, Thank you!
@deltacap0192
@deltacap0192 2 жыл бұрын
Fortunately landed here for an interview purpose. Just 13 minutes into the video and now I will never be able to forget it. No more brush-ups before the interview. It will be a part of my daily routine now. I have always used preconditions, type checks, typecasting, or dummy implementations to escape such scenarios. Never knew that was a violation of this textbook rule. I had tried explanations with practical examples earlier too, but the simplicity of example and language in your video beats all of them. Thank you so much...
@IAmTimCorey
@IAmTimCorey 2 жыл бұрын
I am glad it was so helpful.
@pranaygawand4884
@pranaygawand4884 5 жыл бұрын
Awesome work again Tim! Never understood LSP event after spending hours on the internet reading blogs and articles. Thank you so much!
@IAmTimCorey
@IAmTimCorey 5 жыл бұрын
I'm glad this was helpful to you.
@vero7427
@vero7427 Жыл бұрын
After going through multiple resources these are by far the best SOLID Principle explanations I've come across so far. I have a much better understanding now :)
@IAmTimCorey
@IAmTimCorey Жыл бұрын
Great to hear!
@iandalrymple7255
@iandalrymple7255 2 жыл бұрын
This might sound weird but I must say I regret not watching all of Tim Corey C# videos from the start of my programming journey. Would have saved me a lot of time. Thank you sir for the work you have done.
@IAmTimCorey
@IAmTimCorey 2 жыл бұрын
I appreciate the kind words. I am glad you have found my content so valuable.
@priyankapardesiramachander871
@priyankapardesiramachander871 4 жыл бұрын
I am addicted to your teaching style. Reading these design concepts from books is one thing, but a code example really opens up one's mind for better understanding. Thank you for all the tutorials, and special thanks for making the source code available.
@IAmTimCorey
@IAmTimCorey 4 жыл бұрын
You are most welcome. Thanks for watching.
@mitchellbroue4778
@mitchellbroue4778 4 жыл бұрын
Great video. This is the first presentation that has enough clear explanation to solidify the LSP principles. Full marks.
@IAmTimCorey
@IAmTimCorey 4 жыл бұрын
Glad it was helpful!
@mattak77
@mattak77 3 жыл бұрын
This is by far the best and cleanest explanation with hands on coding. Also some tips for Visual Studio shortcuts, brief explanation for abstract class helped me learn more than SOLID principle. Thank you so much.
@IAmTimCorey
@IAmTimCorey 3 жыл бұрын
Glad it was helpful!
@shenamariedabalos1699
@shenamariedabalos1699 2 жыл бұрын
I try not to skip the ads as a thank you for your amazing content. Thank you.
@IAmTimCorey
@IAmTimCorey 2 жыл бұрын
Thank you!
@xcyron
@xcyron 2 жыл бұрын
Learned so much in these 3 courses so far, this is seriously the best tutorial on SOLID that i came across.
@IAmTimCorey
@IAmTimCorey 2 жыл бұрын
Thank you!
@hayleyha9433
@hayleyha9433 3 жыл бұрын
This is the best explanation on the internet for SOLID. Thank you for making separate videos with code demo for each topic, they are extremely helpful and after watching your seri on this topic, I don't feel vague a bout SOLID anymore
@IAmTimCorey
@IAmTimCorey 3 жыл бұрын
Glad it was helpful!
@sebainones
@sebainones 2 жыл бұрын
One of the best explanations I've ever found on this pricniple that sometimes it could be tricky or confusing. Thanks a lot!
@IAmTimCorey
@IAmTimCorey 2 жыл бұрын
You are welcome.
@bobcat235
@bobcat235 4 жыл бұрын
Tim Corey, you are a gift from God for explaining this stuff. Thankyou!
@IAmTimCorey
@IAmTimCorey 4 жыл бұрын
You are welcome.
@fisheralaric692
@fisheralaric692 3 жыл бұрын
I dont mean to be so off topic but does any of you know a trick to log back into an instagram account?? I was stupid lost my account password. I would appreciate any assistance you can offer me
@alonsobentley3351
@alonsobentley3351 3 жыл бұрын
@Fisher Alaric instablaster =)
@fisheralaric692
@fisheralaric692 3 жыл бұрын
@Alonso Bentley I really appreciate your reply. I got to the site thru google and I'm waiting for the hacking stuff atm. I see it takes quite some time so I will get back to you later with my results.
@fisheralaric692
@fisheralaric692 3 жыл бұрын
@Alonso Bentley it worked and I now got access to my account again. Im so happy! Thanks so much, you saved my account!
@gerardhayden6568
@gerardhayden6568 Жыл бұрын
Tim, your Car/Deckchair analogy reminded me of an old Jeremy Clarkson clip, where he was detailing what makes a supercar, when he said something like "Of course, not everything painted bright red with the engine centrally mounted behind the driver is a supercar" and the camera pans back to revel him standing by a ride-on lawn mower!
@IAmTimCorey
@IAmTimCorey Жыл бұрын
😆
@aimanalnami7655
@aimanalnami7655 2 жыл бұрын
Thanks tim this is real world scenario ... better then shape and rectangle 😂
@IAmTimCorey
@IAmTimCorey 2 жыл бұрын
You are welcome.
@dejamirgianelli6231
@dejamirgianelli6231 4 жыл бұрын
One of the best explanations I've seen at KZbin.
@IAmTimCorey
@IAmTimCorey 4 жыл бұрын
Thank you!
@LarryPeteet
@LarryPeteet 3 жыл бұрын
Thanks Mr Corey. You are a Rockstar. I have been with Microsoft Technology Stack for 25 Years (MSDOS, Microsoft C) and keep trying to learn some of the things you know so well!!
@IAmTimCorey
@IAmTimCorey 3 жыл бұрын
Wow, thanks
@bagratzakaryan8871
@bagratzakaryan8871 Жыл бұрын
Frankly speaking, I read up to 10 articles about LSP and watched multiple videos, and I couldn't really understand the principle of LSP, but your video is perfect, even I do not know C# language, but I know Typescript thought it would be difficult to understand, but not, it's helped me thanks a lot for the explanation.
@IAmTimCorey
@IAmTimCorey Жыл бұрын
Awesome! I’m glad it was helpful.
@pradeepbetty
@pradeepbetty 2 жыл бұрын
Thank goodness,.. At last, a more practical example than the rest of the internet,... Thank you TIM.
@IAmTimCorey
@IAmTimCorey 2 жыл бұрын
You are welcome.
@thomascaedere
@thomascaedere 6 жыл бұрын
Hey Tim, I really like the use cases you used for illustrating these problems. I'm encouraging all of my team members to have a look at this series about SOLID to make sure they are doing the right thing. One thing though, I would use the IManager input type for AssignManager method in stead of IEmployee and make the Manager property in IManaged of type IManager. This way, you're making sure we can only input a manager when assigning the manager. When retrieving the manager from the employee, we are certain the manager can in fact generate a performance review, which would make this implementation more safe i.m.o. It doesn't break anything about the fact that this video is very well explained. Thank you!
@IAmTimCorey
@IAmTimCorey 6 жыл бұрын
I'd have to go back and watch, but this sounds like a reasonable suggestion. Thanks!
@timmyers9798
@timmyers9798 6 жыл бұрын
LOL, "Whatever you do, don't freak out" ... loved that comment. Great video. Thanks man.
@IAmTimCorey
@IAmTimCorey 6 жыл бұрын
I'm glad you enjoyed it.
@Reaper7mk
@Reaper7mk 2 жыл бұрын
What a practical and beautifully sophisticated example. Bravo sir.
@IAmTimCorey
@IAmTimCorey 2 жыл бұрын
You are welcome.
@jesphaylobo8105
@jesphaylobo8105 3 жыл бұрын
That was a super example and a great explanation about interfaces. I now feel comfortable with interfaces.
@tomthelestaff-iamtimcorey7597
@tomthelestaff-iamtimcorey7597 3 жыл бұрын
Thanks for watching and sharing!
@Dame4Lyf3
@Dame4Lyf3 6 жыл бұрын
Great series and have been invaluable to becoming a better programmer, thanks for your time in explaining these concepts to a fledging developer.
@IAmTimCorey
@IAmTimCorey 6 жыл бұрын
I'm happy that it has helped you develop as a programmer. That's why I make these videos.
@Redpill99
@Redpill99 Жыл бұрын
Thank you Tim for all the free content.
@IAmTimCorey
@IAmTimCorey Жыл бұрын
Thank you!
@maricelpurusniuc7038
@maricelpurusniuc7038 3 жыл бұрын
Great series, with just the right amount of technical details and explanations
@IAmTimCorey
@IAmTimCorey 3 жыл бұрын
Thanks!
@kmorgan26
@kmorgan26 5 жыл бұрын
Great stuff, Tim! I have read about inheritance several times before, and now that I've watched this video, I think I have a waaaay better understanding of how to implement it. You have a great way of explaining rather complex concepts! Good on you.
@IAmTimCorey
@IAmTimCorey 5 жыл бұрын
Awesome! I'm glad it was so helpful.
@myemailvl
@myemailvl 5 жыл бұрын
Thank you, Tim! You have a talent to explain everything in a simple way. I appreciate your work very much! Thank's again!;)
@IAmTimCorey
@IAmTimCorey 5 жыл бұрын
You are most welcome. Thanks for watching.
@amnesia3490
@amnesia3490 4 жыл бұрын
It was awesome explanation of Interface, Inheritence and other all that related stuff. Its not only explanation of princple it is also perfect example of understanding inheritence.
@IAmTimCorey
@IAmTimCorey 4 жыл бұрын
Thank you, that is the goal.
@stephenyork7318
@stephenyork7318 4 жыл бұрын
Around 9:00, something I've never considered! Love your work, thanks heaps.
@IAmTimCorey
@IAmTimCorey 4 жыл бұрын
Happy to help!
@paulofernandoee
@paulofernandoee 2 жыл бұрын
Great Series Tim! It's really nice to see the principles blending in and complementing each other. If someday you have the time to make a video about covariance and contravariance, i believe you will be able to explain it in an excellent way, i have tried reading the msdn docs and watching other videos on this matter, i just cant understand it.
@IAmTimCorey
@IAmTimCorey 2 жыл бұрын
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/
@solr4cc
@solr4cc Жыл бұрын
Finally very good explanation of LSP. Great content!
@IAmTimCorey
@IAmTimCorey Жыл бұрын
Thank you!
@Paul-uo9sv
@Paul-uo9sv Жыл бұрын
@@IAmTimCorey Your vids are awesome. thanks
@RaterisimoCBA
@RaterisimoCBA 2 жыл бұрын
Another excellent class. I'll be taking one of your courses soon, I can see myself learning this way. Thank you for having this content for everyone, it's so helpful !
@IAmTimCorey
@IAmTimCorey 2 жыл бұрын
You are welcome.
@SuperBbbbssss
@SuperBbbbssss 6 жыл бұрын
I have all the 5 SOLID principles - thanks for your effort brother.
@IAmTimCorey
@IAmTimCorey 6 жыл бұрын
You are welcome.
@hugogogo13
@hugogogo13 Жыл бұрын
LSP could be summed up as ALP => "Avoid Lazy Polymorphism". Thank you for your videos Tim!
@IAmTimCorey
@IAmTimCorey Жыл бұрын
You are welcome.
@vartikagupta8816
@vartikagupta8816 3 жыл бұрын
How do you find the easiest way to explain things. I think I have understood it for good this time. Thanks Tim!
@tomthelestaff-iamtimcorey7597
@tomthelestaff-iamtimcorey7597 3 жыл бұрын
Great! Thank is the goal. It takes me a few times myself.
@harag9
@harag9 Жыл бұрын
Great explanation and very clear, many thanks Tim. Not sure why I've not seen this video when I've seen your other SOLID videos. hmm.
@IAmTimCorey
@IAmTimCorey Жыл бұрын
Glad it was helpful!
@sbeasley1120
@sbeasley1120 5 жыл бұрын
I like making anything that uses Base in the class name abstract. Because it shouldn’t ever be used on its own. I’m glad that you talked through it here.
@IAmTimCorey
@IAmTimCorey 5 жыл бұрын
Yep, that's a good convention.
@GuRuGeorge03
@GuRuGeorge03 3 жыл бұрын
It really clicked when you said that CEO is not an employee. It immediately gave me the idea that a manager should be any class that implements an IManager interface that can then be dependency injected into any class that has a manager. In other words, getting rid of inheritance is just great, lol
@tomthelestaff-iamtimcorey7597
@tomthelestaff-iamtimcorey7597 3 жыл бұрын
Great, super glad it helped
@RobertMunteanu105
@RobertMunteanu105 2 жыл бұрын
Hey Tim, thanks a lot for this video! I was having a quick look on things. I'm having an interview tomorrow 😄
@IAmTimCorey
@IAmTimCorey 2 жыл бұрын
Best wishes!
@alex44483
@alex44483 6 жыл бұрын
Really enjoying this series, thanks for making it :) You explain things a lot clearer than others
@IAmTimCorey
@IAmTimCorey 6 жыл бұрын
I'm glad you are enjoying it.
@allmhuran
@allmhuran 6 жыл бұрын
Good video. Coming from a relational background, the "correct" solution in my mind is different from the one proposed here. Essentially, I'd say this: The manger of an employee is *not* a property of the employee. It is a relationship between two entities. As such, the solution would be to create a new class to model that relationship. We would then keep the set of all of those relationships in an containing entity which we might call the OrganisationalChart. That's somewhat specific to this example, but that's because the example involves relationships between entities, and the same sort of model should apply to any similar situation - ie, don't model relationships between entities as attributes of those entities - which is something that comes up quite often.
@IAmTimCorey
@IAmTimCorey 6 жыл бұрын
This is how we model that relationship in C# though. When using a class instance as a property, we aren't putting that class into our class (so we aren't putting a Manager into an Employee), we are essentially putting a reference to the other object in our current object (so Employee has a reference to the Manager class, not a copy of it). The classes still exist on their own. In that way, we could actually go up the org chart from any employee all the way to the CEO. We look at the Employee's manager, and then look at that manager's manager, and so on up the chain. I didn't add it but typically I would also include a List that is the subordinates of any Manager. If we create another object that is the relationships (the organizational chart), we are storing information about the Employee outside of the Employee class. That means keeping that data connected to the Employee while outside of its control. That is dangerous. It provides a possible synchronization issue if one changes without the other. If you have the Employee link to an OrgChart object, there is not any really difference then between this solution and directly linking to the Manager except you have added a layer of complexity without gaining any perceivable benefit. That is why, because of how class instances work, it is best in C# to assign a class instance to the Manager property and put it into the Employee class. Besides, if you were to ask me who my manager is, I would not refer to you an OrgChart. I would just tell you. That is what our application is doing.
@allmhuran
@allmhuran 6 жыл бұрын
Yep, I know that's how it's often modelled, for example in the entity framework (which does give the parent a collection of the children as you described). What I'm saying is that I don't think the approach is logically supportable. If I make anything a member of a class, then I'm saying that the class is responsible for that member. But the employee represented by the employee class is not responsible for the relationship between itself and its manager, so the manager (or manager reference) shouldn't be a member of the employee class. The same argument applies to the collection of employees (or employee references) in the manager object. Creating the org chart doesn't store information about the employee outside of the employee class. All of the properties of employees are still stored in employee objects. What the OrgChart does is store information about the relationships which exist between those employee objects. As a "proof by contradiction" of this, consider a company that only has a single employee. This employee has no manager. In fact they can never have a manager given this condition. But the employee can still be fully defined - this is trivially true, because they are in fact an employee. So it is possible to fully define the employee despite the absence of a manager. But if the employee class has a manager reference, and if that reference is null, then the employee has not been fully defined. Ergo, the employee class should not have a member which is a reference to a manager. I realise that this is not the way in which models are typically created (eg, in C#), but I'm not appealing to tradition according to any particular language, I'm looking at it from a more fundamental perspective rooted in predicate logic.
@niyaziozturk3967
@niyaziozturk3967 4 жыл бұрын
Thank you Tim. I studied this four five years ago and totally forgotton. Very good tutorial, thank you!
@IAmTimCorey
@IAmTimCorey 4 жыл бұрын
You're very welcome!
@colin-campbell
@colin-campbell 6 жыл бұрын
Tim Corey for president
@IAmTimCorey
@IAmTimCorey 6 жыл бұрын
Ha! There's a job I don't want. I'm happy making developers' lives easier.
@pw.70
@pw.70 4 жыл бұрын
I found this more intuitive than the Open/Closed Principle. Excellent tutorial - thank you.
@IAmTimCorey
@IAmTimCorey 4 жыл бұрын
You are welcome.
@LarryPeteet
@LarryPeteet 3 жыл бұрын
Suggestion: "Track Active Item in Solution Explorer" under Tools, Options. This would let us watching easily see which file you are in. For example you were talking about Employee and showing Code for Employee but Solution Explorer on the screen was highlighting CEO.cs file.
@IAmTimCorey
@IAmTimCorey 3 жыл бұрын
Noted, thanks.
@mimart3011
@mimart3011 2 жыл бұрын
11:40 I like you mentioned one of the ways how to overcome this. One is have interfaces instead or you can/should/have to write tests to cover the cases where the LSP can be broken
@TheAngelOfDeath01
@TheAngelOfDeath01 6 жыл бұрын
"Learning" this in C++ back in my ooolld science class was a freaking nightmare, especially because of the ability to perform inheritance from MULTIPLE classes, etc. Glad to see you decided to include those abstract classes. ;-) hehe. Thanks for uploading; as always a good and informative video! :D
@IAmTimCorey
@IAmTimCorey 6 жыл бұрын
Multi-inheritance can be ... challenging. Glad you enjoyed the video.
@TheAngelOfDeath01
@TheAngelOfDeath01 6 жыл бұрын
IAmTimCorey meaning you write C++ or JAVA yourself??
@IAmTimCorey
@IAmTimCorey 6 жыл бұрын
Yep. I haven't in a couple years but I've been a consultant off and on for years. In that time I've developed applications in FoxPro, Access, VBA, VB6, C, C++, Java, JavaScript, PowerShell, ObjectiveC, Python, PHP, VB.NET, and Delphi to name a few. At one point I stopped counting at 20+ languages that I had built applications in. I try to focus on C#, SQL, and JavaScript these days as much as I can though.
@TheAngelOfDeath01
@TheAngelOfDeath01 6 жыл бұрын
Whistles. I stuck with VBscript, PHP, JavaScript and a tiny-tiny amount of C++ (just enough to understand the concepts) PHP I'm good at, especially combined with Zend-Framework and MySQL, and the pivotal HTML, JavaScript and CSS combinations.
@IAmTimCorey
@IAmTimCorey 6 жыл бұрын
The trick is to realize that all languages fall roughly into two buckets: functional and object oriented. Once you are comfortable with how one of the buckets work, the differences between languages in that bucket are just syntax. The logic stays the same. So basically, you can think in C# (the concepts) but write in C++ or Java by just figuring out how to do x in the other language. It isn't as efficient (you Google a LOT) but you pick it up pretty quick.
@n9434178
@n9434178 6 жыл бұрын
Thank you Tim ! Very clear and very useful explanation to me. It really is a very complete answer to the question that I posted in response to your OCP video. Looking forward to your next videos!
@IAmTimCorey
@IAmTimCorey 6 жыл бұрын
Great!
@Neo8019
@Neo8019 4 жыл бұрын
Great tutorial, thanks! You create one of the best ones out there. Keep up the great work.
@IAmTimCorey
@IAmTimCorey 4 жыл бұрын
Thank you!
@shacham85
@shacham85 6 жыл бұрын
Thank you for this. This is by far the best explanation of Liskovs principle I have seen yet.
@IAmTimCorey
@IAmTimCorey 6 жыл бұрын
I am glad you found it valuable.
@xcyron
@xcyron 2 жыл бұрын
When i finished the second video (O in Solid) i was like, wait, how do i acces additional methods and properties that aren't part of the interface now? And here we are at the solution for that. Amazing tutorial series.
@IAmTimCorey
@IAmTimCorey 2 жыл бұрын
I am glad it was so helpful.
@callumhaynes1384
@callumhaynes1384 4 жыл бұрын
Best explanation i have seen, thanks for jumping straight to the code. I have always struggled to understand this principle, but now i understand it. Cheers Tim :)
@IAmTimCorey
@IAmTimCorey 4 жыл бұрын
Glad it helped!
@rasikagayangunarathna
@rasikagayangunarathna 4 жыл бұрын
Thank you very much for this valuable tutorial.
@IAmTimCorey
@IAmTimCorey 4 жыл бұрын
You are welcome.
@NeoPlanetx
@NeoPlanetx 6 жыл бұрын
Great material Tim, keep up to good work! Thank's for helping the community with your knowledgment!
@IAmTimCorey
@IAmTimCorey 6 жыл бұрын
I appreciate the kind words.
@pierreplourde
@pierreplourde 2 жыл бұрын
Covariance and contravariance: I feel like I’m back in my Tensor Calculus or General Relativity class!
@IAmTimCorey
@IAmTimCorey 2 жыл бұрын
I did not enjoy courses like that.
@TaSwavo
@TaSwavo 3 ай бұрын
When you first started I thought 'here we go again! messing with something in a weird way when it's easily fixed' but it made sense in the end. I like S and L but still see as many problems as solutions with OCP to be honest for the work I do. Before this I would have added a variable to all Employees saying IsManager and IsCEO and then had if statements within Employee to control usage of methods. Messier and worse if things were more complex.
@IAmTimCorey
@IAmTimCorey 3 ай бұрын
There's always a tradeoff. That's the biggest trick to learn in software development - when to accept which tradeoffs.
@harag9
@harag9 6 жыл бұрын
Great video again Tim, thanks. Nice and clean and well explained! However, I think I spotted an error on the "IManaged" interface - the property "Manager" should be an IManager type not an IEmployee type. Because when a "Manager" is assigned to that property you still want to have access to the CreateReports method the Manager has. Hope this makes sense.
@IAmTimCorey
@IAmTimCorey 6 жыл бұрын
Yep, I didn't catch that. It would give the variable more access to the manager's methods and properties more easily. I would definitely change that.
@peteredenburg6464
@peteredenburg6464 6 жыл бұрын
Hello Harag and Tim, I tried implementing the change suggested here, but it has some more trickle downs that, when all are changed as a consequence of this first adaptation, I end up with errors in the code that I am not quite yet capable of fixing myself. This is my lack of knowledge of of c# course, but is it possible to provide a new download of the completed project with this change implemented? Thanks in advance.
@peteredenburg6464
@peteredenburg6464 6 жыл бұрын
Sorry, I found it. Now it works after changing in the proper places.
@darrenbrook4641
@darrenbrook4641 5 жыл бұрын
@@peteredenburg6464 Do you have code with those changes please?
@ruifeng4901
@ruifeng4901 3 жыл бұрын
Thank you Tim! Your video is very thought-provoking! After watching this video. As to the example you mentioned in the end about both cars and desks have wheels doesn't mean they're related enough to have an inheritance structure. It reminds of me the difference between 'is-a' and 'has-a' reslationship. Is it possible that you make some videos to illustrate these two relationships using some examples? Thanks again!
@IAmTimCorey
@IAmTimCorey 3 жыл бұрын
Thanks for the suggestion. I have added it to the list of possible future topics.
@nikolaykolev5431
@nikolaykolev5431 6 жыл бұрын
Hey Tim, great content, please keep up the good work, looking forward :)
@IAmTimCorey
@IAmTimCorey 6 жыл бұрын
Thanks and will do.
@torrvic1156
@torrvic1156 Жыл бұрын
Thank you so much for excellent explanation of a very complicated matter Tim! This is really helpful and useful in the real life applications. I though I will never understand it properly. But it seems like I am starting to figure it out after you video. In global it is all about keeping wise balance between inheritance and interfaces. All of the three types of employees should have everything common in their base class and differences should be shown via interfaces. That is how I understood it.
@IAmTimCorey
@IAmTimCorey Жыл бұрын
I am glad it was helpful.
@amarnathsharma
@amarnathsharma 4 ай бұрын
In LSP, If T extends S and you just replace T with S and nothing else, no method behaviour should change but you said its ok.
@IAmTimCorey
@IAmTimCorey 4 ай бұрын
That's the wrong direction. The parent can be replaced by the child. The child might have more options, and therefore cannot always be replaced by the parent.
@lorenzolomeli3661
@lorenzolomeli3661 2 жыл бұрын
Good example, I am thinking if somebody understand the OOP concepts, automatically you can apply these SOLID design principles.
@IAmTimCorey
@IAmTimCorey 2 жыл бұрын
Thanks!
@zulhishamtan4308
@zulhishamtan4308 3 жыл бұрын
This is really good. Thank you very much.
@IAmTimCorey
@IAmTimCorey 3 жыл бұрын
Glad you like it!
@nagamanikanta4251
@nagamanikanta4251 3 жыл бұрын
Thanks for the videos. It was a good explanation with a real-world example. could you please make one video applying the solid principles in a simple project?.
@georginakissinger3492
@georginakissinger3492 3 жыл бұрын
Best explanation ever. Thank you Tim Corey.
@tomthelestaff-iamtimcorey7597
@tomthelestaff-iamtimcorey7597 3 жыл бұрын
Much appreciated, thanks for watching
@alinawaz4034
@alinawaz4034 6 жыл бұрын
Your videos are Amazing Like Always Thanks! for sharing your knowledge with us May Allah Increase your knowledge! and our also.
@IAmTimCorey
@IAmTimCorey 6 жыл бұрын
Thanks!
@shivaayJikiduniya
@shivaayJikiduniya 4 жыл бұрын
Thanks tim, this helps me a lot. Awesome bro!!!
@IAmTimCorey
@IAmTimCorey 4 жыл бұрын
You are welcome.
@Oleg-ng7ss
@Oleg-ng7ss 3 жыл бұрын
Thanks! Good explanation. Very helpful for me. Now I understand what is LSP.
@tomthelestaff-iamtimcorey7597
@tomthelestaff-iamtimcorey7597 3 жыл бұрын
Thanks for watching the video and for sharing your thoughts.
@filip4092
@filip4092 3 жыл бұрын
Perfect explanation thanks a lot.
@tomthelestaff-iamtimcorey7597
@tomthelestaff-iamtimcorey7597 3 жыл бұрын
We are glad you found it helpful and appreciate your sharing your thoughts. Thanks for being a part of this great community.
@petermanger9047
@petermanger9047 3 жыл бұрын
So LSP is basically saying don't change anything and you'll be fine... I love rules - I like the cracking sound as they break! (btw, I actually really like this rule - it basically enforces the "no surprises" principal of coding, and nothing is more annoying than having to write code sometime down the pipe that has to check instance type to behave properly).
@IAmTimCorey
@IAmTimCorey 3 жыл бұрын
Thanks for sharing your thoughts
@CybeargPlays
@CybeargPlays 5 жыл бұрын
Although I really appreciate your example, and its straightforwardness is part of that, one easy real-life problem I could see would be the GeneratePerformanceReview method having a lot of code in it. In this current design, that code would need to be replicated among all IManager classes. Since C# does not support multiple inheritance, what would be your solution in such a situation where both the IEmployee and the IManager (and, just for fun, maybe also IManaged) came with a lot of code that would be nice to reuse. Composition? I could see all that extensive code for how to generate a performance review being pulled out into, for example, a PerformanceReviewGenerator class (which, for good Unit Testing, would necessitate an IPerformanceReviewGenerator interface) that Managers and CEOs require (or instantiate) as part of their construction, and GeneratePerformanceReview just becomes a wrapper for calling the PerformanceReviewGenerator class's GeneratePerformanceReview method. Is that the approach you'd recommend in practice?
@IAmTimCorey
@IAmTimCorey 5 жыл бұрын
Yep. The key, though, would be to identify if performance reviews would change significantly between employee types. If so then you would probably have a method in the employee type class that managed the review (calls a bunch of methods to set it all up). If not, you could just have the review class injected into the employee. A lot of different approaches here but you are correct that we don't want to create duplicate code.
@ashishdawale4790
@ashishdawale4790 5 жыл бұрын
Very well explained. Thank you Tim!
@IAmTimCorey
@IAmTimCorey 5 жыл бұрын
You are most welcome. Thanks for watching.
@lesmonkmorison2828
@lesmonkmorison2828 3 жыл бұрын
another great video Tim, thanks much.
@IAmTimCorey
@IAmTimCorey 3 жыл бұрын
You are welcome.
@PS-vj6jz
@PS-vj6jz 2 жыл бұрын
Perfect. Thanks. Hello from Russia (o.o)/
@IAmTimCorey
@IAmTimCorey 2 жыл бұрын
You are welcome.
@jasonk.3595
@jasonk.3595 6 жыл бұрын
Thank you Tim, your videos are excellent. This video in particular helped me a lot. Much appreciated. Cheers!
@IAmTimCorey
@IAmTimCorey 6 жыл бұрын
Awesome!
@Guacamole42
@Guacamole42 4 жыл бұрын
Covariance and contravariance allow us to be flexible when dealing with class hierarchy. It is different from what you said in this video.
@IAmTimCorey
@IAmTimCorey 4 жыл бұрын
How so?
@olliegelton5976
@olliegelton5976 Жыл бұрын
very nice.. thank you Tim
@IAmTimCorey
@IAmTimCorey Жыл бұрын
You are welcome.
@thembinkosimtsweni4685
@thembinkosimtsweni4685 Жыл бұрын
I think it would've been better to have Employee as ManagedEmployee and have BaseEmployee as Employee, with the way you have written the code, what do you think?
@longuinni
@longuinni 6 жыл бұрын
Great video Tim. I think it's the first time that I really understood the LSP. But I've a question, do you think that the access modifier in the base class could be protected over public?
@IAmTimCorey
@IAmTimCorey 6 жыл бұрын
Yes, good catch. That would have been something good to point out (and implement). I just forgot to do so.
@longuinni
@longuinni 6 жыл бұрын
Great. I think I'm learning... slowly but learning. I'm look forward for the Interface segregation principle video
@catrielportela1885
@catrielportela1885 7 ай бұрын
Hello Tim, great video men! I have a quick question, What happens if i need in my code to distinguish between different employees type, for example, i want to do something if the employee is Staff and other thing if is Manager. How would i be able to distinguish them apart if not by a employeeType attribute? Tell me your opinion! Thxxxx
@tsachigal1744
@tsachigal1744 Жыл бұрын
Best explanation. Thank you
@IAmTimCorey
@IAmTimCorey Жыл бұрын
You are welcome.
@RoyWagemakers
@RoyWagemakers Жыл бұрын
Great video. Easy to follow
@IAmTimCorey
@IAmTimCorey Жыл бұрын
Great to hear!
@HawkEyeExplorers
@HawkEyeExplorers 2 жыл бұрын
Great explanation. Thank you
@IAmTimCorey
@IAmTimCorey 2 жыл бұрын
Glad it was helpful!
@araksabramovic6156
@araksabramovic6156 Жыл бұрын
This video gave me an offer) Thank you bro
@IAmTimCorey
@IAmTimCorey Жыл бұрын
Awesome!
@vinuhosanagar1
@vinuhosanagar1 6 жыл бұрын
Best explanation ever. Thank you
@IAmTimCorey
@IAmTimCorey 6 жыл бұрын
I'm glad it came through clearly. It can be a tricky one.
@19gauravmittal91
@19gauravmittal91 4 жыл бұрын
Thanks Tim. you made it so simple.
@IAmTimCorey
@IAmTimCorey 4 жыл бұрын
You are welcome.
@MrDanieldamianov
@MrDanieldamianov 4 жыл бұрын
Helpful as always
@IAmTimCorey
@IAmTimCorey 4 жыл бұрын
Thank you!
@hackdan
@hackdan 3 жыл бұрын
Good principles never die
@tomthelestaff-iamtimcorey7597
@tomthelestaff-iamtimcorey7597 3 жыл бұрын
Truth
@CybeargPlays
@CybeargPlays 5 жыл бұрын
Naming things is hard, but might I retroactively suggest Employee be renamed to ManagedEmployee and BaseEmployee be renamed to Employee? Great video!
@IAmTimCorey
@IAmTimCorey 5 жыл бұрын
Thanks for the suggestion and you are correct, naming is hard.
@soucianceeqdamrashti8175
@soucianceeqdamrashti8175 4 жыл бұрын
Really well explained with good examples!
@IAmTimCorey
@IAmTimCorey 4 жыл бұрын
Thanks!
@thedude6810
@thedude6810 Жыл бұрын
Hopefully the business analyst or the customer explained things correctly.
@avitwito1734
@avitwito1734 6 жыл бұрын
Great tutorial. love your channel
@IAmTimCorey
@IAmTimCorey 6 жыл бұрын
Thanks!
@canpehlivan5090
@canpehlivan5090 6 ай бұрын
Hey Tim! Thanks for the video, man!
@IAmTimCorey
@IAmTimCorey 6 ай бұрын
You are welcome.
@VinuP2023
@VinuP2023 5 жыл бұрын
Tim, In a reply to a question you said "OOP can get complex but the key is to learn it slow, not try to dive into the deep end. Get comfortable with classes first (static and instantiated). Then work with inheritance and interfaces. In the meantime, get really comfortable passing class instances around (and understanding how they don't actually move around or copy). Once you are comfortable with all of that, then move into SOLID." Can you plese tell me what do you mean by 1.get really comfortable passing class instances around 2. and understanding how they don't actually move around or copy
@IAmTimCorey
@IAmTimCorey 5 жыл бұрын
Basically, get used to using class instances as variables. So if you have Person p = new Person(), get used to passing that "p" variable into methods, modifying it in the method, and realizing you don't have to pass that variable back because the original location has the changes already. Remember that you are passing around the address to the house you built, not a copy of the house. So when someone who has the correct address makes a change, everyone who has that address can see the change.
@AnotherFancyUser
@AnotherFancyUser 2 жыл бұрын
Ok, I'm at 13:52 when he explained that a CEO is not an Employee because it fails the "is a" as a CEO does not have a Manager. I could be going ahead on the video or be wrong entirely, but wouldn't it be better to take out the Manager property (has a ) in the Employee class and create an interface called IHaveManager and implement it on the classes that has a manager?.
@IAmTimCorey
@IAmTimCorey 2 жыл бұрын
Pretty sure I explain it later on.
@peternguyen9382
@peternguyen9382 5 ай бұрын
Thanks for your work! I have a question, Why we need to replace instance of parent class by instance of child class? in which case we need to do that? Is it because we want polymorphism to be happened without any problems. Thanks
@IAmTimCorey
@IAmTimCorey 5 ай бұрын
That's a common use-case. For instance, your application might rely on EmailClient, but you end up writing a child class called GoogleEmailClient and another called OutlookEmailClient. You can then use either in the place of the original class without disrupting anything.
@peternguyen9382
@peternguyen9382 5 ай бұрын
@@IAmTimCorey thanks! your channel helps me alot!
@Kavorka666
@Kavorka666 10 ай бұрын
Quick Question , if its not too much trouble. Why do we need to add IEmployee interface? Can't we just use BaseEmployee class to inherit from others?
@johnikeson3114
@johnikeson3114 9 ай бұрын
You have an IManaged interface which needs to extend to the IEmployee interface. Interface can't extend a concrete class. IManaged : BaseEmployee [x]
@VijayendraDGhatge
@VijayendraDGhatge 4 жыл бұрын
Great explanation, cleared everthing
@IAmTimCorey
@IAmTimCorey 4 жыл бұрын
Glad it helped!
Please Help Barry Choose His Real Son
00:23
Garri Creative
Рет қаралды 24 МЛН
Секрет фокусника! #shorts
00:15
Роман Magic
Рет қаралды 60 МЛН
Мы сделали гигантские сухарики!  #большаяеда
00:44
How Senior Programmers ACTUALLY Write Code
13:37
Thriving Technologist
Рет қаралды 1,5 МЛН
Covariance and Contravariance
13:31
Christopher Okhravi
Рет қаралды 13 М.
How principled coders outperform the competition
11:11
Coderized
Рет қаралды 1,7 МЛН
Uncle Bob’s SOLID Principles Made Easy 🍀 - In Python!
19:09
ArjanCodes
Рет қаралды 293 М.
SOLID Principles: Do You Really Understand Them?
7:04
Alex Hyett
Рет қаралды 167 М.
Liskov Substitution Principle
20:16
Christopher Okhravi
Рет қаралды 12 М.
Please Help Barry Choose His Real Son
00:23
Garri Creative
Рет қаралды 24 МЛН