Low Level Design 107 | Liskov Substitution Principle | 2022 | System Design

  Рет қаралды 62,224

sudoCODE

sudoCODE

Күн бұрын

Пікірлер: 92
@PrateekSaini
@PrateekSaini 10 ай бұрын
In the context of the example of the Shape class and its functionality i.e. just to compute area, there is nothing wrong with the Square class extending from the Rectangle class. It does not violate the LSP either, you can actually replace any instance of the Rectangle class with an instance of the Square class. However if you have a Rectangle class with setter methods for both Lenth and Breath, making them mutable independently of each other, then extending the Square class from the Rectangle class would violate the LSP. Because calling setHeight() and setWidth() on an instance of Square class would change the other property, which in purely programming construct might fail a few tests. An important thing not to miss here is the context and functionalities the parent class is providing. They must work even after substituting with an instance of the child/derived class.
@DecentProgrammer
@DecentProgrammer Жыл бұрын
One of the best tutors on youtube. Thanks yogita for the series. :)
@AkashVerma-l7y
@AkashVerma-l7y Жыл бұрын
You actually told the essence of LSP. Thanks for that.🙂
@sushmitagoswami2033
@sushmitagoswami2033 9 ай бұрын
Your videos are always crisp and to the point. ❤
@meetkgp
@meetkgp Жыл бұрын
If we implement the methods again in the child class when they are already present in the parent class (04:09), then what is the point of inheritance here. Also, the implementation in both parent and child classes is also exactly the same. Aren't we redoing the work and doing code duplication?
@_rameez
@_rameez 4 ай бұрын
exactly my point
@charan775
@charan775 Ай бұрын
probably given a wrong example. but you can image beverage item implementing get price with some custom logic, based on what is the item because bevarages cost more but every other item we can follow standard price
@manubabu8547
@manubabu8547 29 күн бұрын
Thanks you so much Yogitha Madam, this is invaluable, you have explained it with very simple and effective exampes.
@ganeshk8682
@ganeshk8682 2 жыл бұрын
amazing.. it will be icing on the cake if you make a video on SOLID with a system design example..like parking lot
@simply_homemaking
@simply_homemaking 2 жыл бұрын
Please add the videos frequently .. i am literally waiting for your videos
@khushalishah4609
@khushalishah4609 2 жыл бұрын
Amazing series, Thank You so much ma'am for the awesome LLD series. and is here we missing video for open - close principle? or you'll cover in upcoming videos
@ShubhamKumar-sz1fl
@ShubhamKumar-sz1fl 2 жыл бұрын
Hi Mam, Very informative video. Just wanted to know if the video for open closed principle pending or I might have missed that video. Thank you for producing such a quality content.
@ankurbose7672
@ankurbose7672 Жыл бұрын
Hi Yogita, can you please make a video on the open closed principle "O" of SOLID? Is there a reason for that being left out?
@nids9975
@nids9975 Жыл бұрын
Same question.
@sahilarora4602
@sahilarora4602 2 жыл бұрын
I will make to big company, if not today if not tomorrow but very soooon . BTW Thanks for the help for the course for free .
@SakshiSingh-arcane05
@SakshiSingh-arcane05 Жыл бұрын
what do we mean by breaking here in the method? even after the implementation of getPrice in BeverageItem(), if I replace menuItem object by beverageItem object, unless we specify the correct instance at creation, we would get the price of beverageItem without discount right? So what are we trying to prevent here? Ensuring that at least we can call the method from both child and parent class or we need to ensure that even if the superClass is replaced by subclass object we get the same response?
@ksmwsk
@ksmwsk 9 ай бұрын
I'm with you, this is not a violation of the LSP
@jasper5016
@jasper5016 2 жыл бұрын
This is a treasure of knowledge. Thanks a lot for this video.
@subhasishhalder4817
@subhasishhalder4817 2 жыл бұрын
Very well explained. One another point I think we can keep in mind is if you are providing any extra functionality (some public methods..) in child class which is not been covered by parent class then its breaking LSP. That's when you will get error when you replace the child instance by parent instance when calling the extra functionality. Correct me if I am wrong.
@sudocode
@sudocode 2 жыл бұрын
The theorem says about replacing parent instance by child instance :)
@prashantrajawat2829
@prashantrajawat2829 2 жыл бұрын
@@sudocode Mam please complete remaining video of solid principles. Your explanation is amazing 👍
@aneksingh4496
@aneksingh4496 Жыл бұрын
best video on Liskov
@RiteshKumar-ge5ee
@RiteshKumar-ge5ee 2 жыл бұрын
Thanks for the amazing content. But I'm confused, have you skipped Open close principle intentionally or I'm missing something?
@sudocode
@sudocode 2 жыл бұрын
We lost the video for ocp, only left with audio. Will record again and release.
@RiteshKumar-ge5ee
@RiteshKumar-ge5ee 2 жыл бұрын
@@sudocode Thanks for clarifying. Keep up the good work you are doing. Thanks for the content once again.
@shubhamsonal5871
@shubhamsonal5871 2 жыл бұрын
@@sudocode Can you please upload the video for ocp, its a missing piece in the puzzle and the series, Thanks in advance , eagerly waiting !
@brianv62
@brianv62 10 ай бұрын
Great explanation! Thanks!
@nagendramishra164
@nagendramishra164 Жыл бұрын
Your api rate limit vedio is very awesome👍
@lostanmol
@lostanmol Жыл бұрын
Second principal video 'O' is not available in the playlist and i can't even find it in your channel
@fanclub69
@fanclub69 Жыл бұрын
The way you explain is really appreciated. If I follow it correctly please clarify once @4:44 A private method in MenuItem class can't be overridden in BreverageItem class.
@maheshkumartangella5516
@maheshkumartangella5516 2 жыл бұрын
Can you please also make a video on Open-Close principle ? It's confuses me the most
@koreanmix1902
@koreanmix1902 Жыл бұрын
Well what should I say, i was actually unable to understand this 3rd principle but after watching this video I clearly understand the concept....
@Arjun-tg1go
@Arjun-tg1go 2 жыл бұрын
Sorry to say but first example is actually example of open close principle where client code is remain the same due to use of polymorphism (without any instance of condition) LSP mainly deals with 3 concepts of subclass 1. Precondition should not be strengthened- meaning input param validations on overriding methods should be not be more strict than overridden methods 2. Postconditions can’t be weakened- meaning if your parent class method returns a String object in all scenarios then overridden method also should return String and not Null(for exception scenarios) 3. Invariants must be preserved - meaning internal state of object(parent) should be correctly preserved by subclass
@sudocode
@sudocode 2 жыл бұрын
You are right with respect to what ocp is but in first example here, Liskov is being violated because as per Liskov, substituting a child instance instead of a parent instance should not require any checks in client code. It can be easy to confuse with ocp because of an overlap. It would be great if you can share the source for the above 3 points. I have taken the first example from the book of four. I can link it.
@Arjun-tg1go
@Arjun-tg1go 2 жыл бұрын
@@sudocode let me check gof for first example. I used wiki for those 3 points en.m.wikipedia.org/wiki/Liskov_substitution_principle
@Arjun-tg1go
@Arjun-tg1go 2 жыл бұрын
As far as I have checked, gof book does not explain LSP, It’s only for design patterns.
@SakshiSingh-arcane05
@SakshiSingh-arcane05 Жыл бұрын
@@sudocode Great video! What I fail to understand is, if "objects of superclass should be replaceable by objects of subclass" and in this case we replace menuItem() by beverageItem(), we would not get the correct value( as discount would be 0), so essentially what are we trying to prevent by creating a getMethod inside beverageItem()? To get the right response (i.e. with discount) I would have to be mindful of the type of object I create right?
@fazeelrazzaq4936
@fazeelrazzaq4936 2 жыл бұрын
When you added a new private function to the menuItem. Haven't you break the Open-Close principle of the SOLID? Which states that classes should be open for extension but closed for modification?
@vikas4483
@vikas4483 2 жыл бұрын
LSP is an extension of Open Close Principle. But in above example LSP is violating OCP.
@sandipbhaumik
@sandipbhaumik Жыл бұрын
On time 4:00 min you said the code is a violation but on 5:53 you are saying the same code as not violation to LS. Little confused around it.
@tushardudhatra3478
@tushardudhatra3478 Жыл бұрын
Thank you for the explanation, it's helpful. I have one question: In java service with persistence layer what normally I have seen: There are entities which shares some common fields such as ID, createTime, UpdateTime etc.. So what people normally do is they create BaseEntity where they will have these three fields and all other fields will be specified in child (or main entity classes). Here I believe Parent class (BaseEntity) and child classes (say UserEntity) are not replaceable when passing to some function. Or is it ? So in this design are we violating Liskov's principle ?
@arvindjaiswal8013
@arvindjaiswal8013 Жыл бұрын
For some situations, you have to think mindfully and hence the flexibility comes in. Think about it, where exactly would you use BaseEntity in your service class? Would you do that ever? No, right? So, you don't have to think of the substitutions ever in case. On the other hand, if you have exposed a Shape class and the children classes like Square, Rectangle or Circle, you may very well use List shapes in your service classes for some generalised answers like getting total areas or the sum of areas, etc.
@satishkumar1809
@satishkumar1809 Жыл бұрын
@yogita, you missed to make open-close principle video
@bhavyabansal1143
@bhavyabansal1143 2 жыл бұрын
Thanks for the amazing videos, which course are you recommending on educative ? Link seems to be showing something else.
@harshitbajpai4942
@harshitbajpai4942 2 жыл бұрын
TBH, I don't think the example of square/rectangle was less confusing or even correct. Yes, we have to be mindful but it still fully follows LSP. I can replace all instances of areaCalculator for square with rectangle and the functionality will not be broken in any way. A bad way to satisfy the principle but nonetheless it does satisfy it. The example of getPrice() was fully correct though.
@lurker4069
@lurker4069 2 жыл бұрын
Is it just me who can't find the Open-Closed Principle video in the SOLID principles list?
@TonyStark90743
@TonyStark90743 2 жыл бұрын
there is none
@mayanktolani7608
@mayanktolani7608 7 ай бұрын
You said that we define a "private" function getDiscount in MenuItem class and override it in the BeverageItem class, but private methods cannot be overridden.
@manikantapunnam1189
@manikantapunnam1189 Жыл бұрын
Hi Ma'am, Well explanation!!! Can i extend the functionality of a child class if needed like adding new functions to the child class along with the existing methods of parent class
@sudocode
@sudocode Жыл бұрын
Yes, you can
@shridhar_rao
@shridhar_rao 2 жыл бұрын
Thanks a lot!
@digvijaychauhan7312
@digvijaychauhan7312 2 жыл бұрын
I am wondering why such less views. Keep on doing the good work. We benefited from these videos. Happy to clear my concepts by watching your videos. Waiting for AOP Spring videos. Or are they already there?
@triptiverma6185
@triptiverma6185 Жыл бұрын
can we plz have 2nd principle OCP that is missing
@shreyashachoudhary480
@shreyashachoudhary480 2 жыл бұрын
Amazing!
@bablushaw6856
@bablushaw6856 2 жыл бұрын
Yogita, Thanks for the video. I have some questions: 1. While designing Menu class it seems like I have to think of the future cases like discount etc and after designing when a new requirement comes which needs to extend Menu class and add some features then I will have to refactor Menu again. Is it right? 2. Suppose, rectangle has a method getLeftArmLength() (Just say this method returns length of an arm) then Inheriting from rectangle I can use it in square as well. But inheriting from shape I have to implement that method both on rectangle and square. Doesn't it reduces code re-usability?
@rahulraj94391
@rahulraj94391 2 жыл бұрын
I think these principle are very subjective, and one can argue over how his design is better, over others in many ways.
@ksansudeen
@ksansudeen 2 жыл бұрын
Hi , Thanks for the video. but incase if we have to play more with discount lets say its based on certain % based on some inputs we may violate Single responsibility case. normally such things should be separate class and instance should be in base class. so who wants play with discount they can create object instance for remain it is null.
@viralyogi
@viralyogi Жыл бұрын
Can we override private method getDiscount() from parent class to child class BeverageItem? Needs little bit clarity on this.
@sudocode
@sudocode Жыл бұрын
Yes you can
@viralyogi
@viralyogi Жыл бұрын
@@sudocode I think private method can't be overridden. Then how this works here. Please help me out.
@ayushmandhar9215
@ayushmandhar9215 11 ай бұрын
why are getDiscount functions private
@sagaravhad5198
@sagaravhad5198 Жыл бұрын
First of all, thanks for making in detail video. You create very good content to refer. One request, could you please plan to upload video on 'Open Close Principle' soon.
@sudocode
@sudocode Жыл бұрын
Sure. It will be uploaded soon.
@shridhar_rao
@shridhar_rao 2 жыл бұрын
Real life code example at 2:58
@shabeebrp3225
@shabeebrp3225 2 жыл бұрын
LSP cannot be explained simpler than this 😇 How is having "private double getDiscount()" method only in BeverageItem gonna break LSP ? as this is a private method, inheritance/method override is not applicable here , so it doesn't violate LSP.
@sudocode
@sudocode 2 жыл бұрын
It won’t. Let me know where it is mentioned in time stamp. Might be an error in speaking or slides.
@shabeebrp3225
@shabeebrp3225 2 жыл бұрын
@@sudocode kzbin.info/www/bejne/fpOqdaKYqd2tjc0
@sanketskhandekar
@sanketskhandekar 2 жыл бұрын
@@sudocode 4:48
@VIVEKKUMAR-mh9dc
@VIVEKKUMAR-mh9dc 2 жыл бұрын
difficult to understand the content as you are speaking and I have to visualize your entire spoken code in my mind....it would be good if you write and show and speak along writing the code...
@sandeeppandey3594
@sandeeppandey3594 8 ай бұрын
True..!!
@allaboutcricket7728
@allaboutcricket7728 2 жыл бұрын
Hi Ma'am, Can you please add Open Closed Principle Video too?
@sibashisnayak7449
@sibashisnayak7449 2 жыл бұрын
Thanks mam
@hmh7028
@hmh7028 Жыл бұрын
Can you please include the open close principle, its been long now...
@srinivasaraoavagadda4648
@srinivasaraoavagadda4648 2 жыл бұрын
how many of you are waiting for OCP video ? :P
@sampathreddy024
@sampathreddy024 2 жыл бұрын
It means subclass should not have any specific methods which are not there in super class and subclass can have only private methods
@sampathreddy024
@sampathreddy024 2 жыл бұрын
This is my understanding some one confirm please @sudoCode
@NavneetVermalivefree
@NavneetVermalivefree 2 жыл бұрын
I think the first example was great. You could have done a better job in explaining the second example. The second example was not that intuitive. If you could have provided the code for second example, that would have helped a lot.. :)
@sudocode
@sudocode 2 жыл бұрын
Agreed.
@Mohamed-uf5jh
@Mohamed-uf5jh Жыл бұрын
Very well explained thanks!
@shatendrasingh6273
@shatendrasingh6273 2 жыл бұрын
For more clarity, follow : www.oodesign.com/liskov-s-substitution-principle
@DeviTheDeveloper
@DeviTheDeveloper 17 күн бұрын
Explanation not sufficient for beginner. especially for example of shape, rectangle and square . I get it. But i hope it could be better if you explain how mock comes to picture
@rishabhgupta734
@rishabhgupta734 2 жыл бұрын
1. The video was crisp and upto the point with awesome explanation. 2. #crush updated😆
@nileshjarad1584
@nileshjarad1584 2 жыл бұрын
Loved it. I think need on correction here. We can not override the Private method. We can Hide the method using given example. kzbin.info/www/bejne/fpOqdaKYqd2tjc0
@debmalyapan53
@debmalyapan53 2 жыл бұрын
series agle saal khatam hoga lag rha h.
@NITISHKUMAR-rc4bp
@NITISHKUMAR-rc4bp 2 жыл бұрын
Dude she is a software engineer as well she has to take care of her job also . Please be grateful for such wonderful content. Thanks
@sudocode
@sudocode 2 жыл бұрын
Thank you for having my back Nitish. I have stepped up to be an engineering manager last quarter. I am trying my best to push content but I don’t want to compromise on quality. This quarter hopefully we finish the series 🙏
@vilasmahalle
@vilasmahalle 8 ай бұрын
Sorry but Not so clear...
@vikaspathak2411
@vikaspathak2411 2 жыл бұрын
What if we define the getPrice() in the MenuItem class only with a parameter named "discount" and we set its default value to 0. int getPrice(int discount = 0) { return this.price - discount * this.price/100} Now when we want to calculate price for BeverageItem we simply use the BeverageItem instance (bev_item) and do this --> bev_item.getPrice(discount = 0) With such implementation can we say that LSP is followed correctly ?
@sudocode
@sudocode 2 жыл бұрын
The idea is that caller should not know about the discount.
@sankalparora9374
@sankalparora9374 Жыл бұрын
Amazing!
Sigma Kid Mistake #funny #sigma
00:17
CRAZY GREAPA
Рет қаралды 24 МЛН
Lamborghini vs Smoke 😱
00:38
Topper Guild
Рет қаралды 64 МЛН
Liskov Substitution Principle
20:16
Christopher Okhravi
Рет қаралды 14 М.
Liskov Substitution Principle: The "L" in SOLID Made Simple
15:10
Coder's Gyan
Рет қаралды 3,1 М.
Liskov: The Liskov Substitution Principle
4:23
Turing Awardee Clips
Рет қаралды 23 М.
SOLID Principles: Do You Really Understand Them?
7:04
Alex Hyett
Рет қаралды 214 М.
Liskov's Substitution Principle | SOLID Design Principles (ep 1 part 1)
16:08
Christopher Okhravi
Рет қаралды 160 М.
Sigma Kid Mistake #funny #sigma
00:17
CRAZY GREAPA
Рет қаралды 24 МЛН