1.1 Liskov Substitution Principle (LSP) with Solution in Java - SOLID Principles of Low Level Design

  Рет қаралды 94,135

Concept && Coding - by Shrayansh

Concept && Coding - by Shrayansh

Күн бұрын

this is one of the important SOLID principle. And covered its both Problem and Solution
➡️ Become a Member: / @conceptandcoding

Пікірлер: 135
@ankitgoyal8556
@ankitgoyal8556 7 ай бұрын
KZbin and people like you have made life easier, thankuu.
@anuraggupta6277
@anuraggupta6277 Жыл бұрын
One suggestion - hasEngine could have values - true and false. So instead of returning null, we could have returned false, and it would not break. For this example, we could have taken something like engineType instead of engine. In that case, cycle will have to return null. PS - I am new to these topics. Please correct me if i am wrong 🙂
@ConceptandCoding
@ConceptandCoding Жыл бұрын
:) yes, i think you got the point. Enginetype can be better functionality. but hasEngine is returning Boolean class type, so null is one of the valid return type here.
@janpost8598
@janpost8598 Жыл бұрын
I was thinking the same thing. But then a car who should have an engine could have no (hasEngine returns false) engine. So it perfectly illustrates why a bicycle returns a null and shouldn't have the hasEngine method in the first place.
@12345bcpraful
@12345bcpraful 10 ай бұрын
@anuragupta I have same question in my mind also. Yes if we use engineType functionality it will be better instead of hasEngine. Thank you shreyansh sir.
@Ricky-jr7io
@Ricky-jr7io Жыл бұрын
An excellent explanation of Liskov's Substitution principle. I work primarily with python and javascript, and your explanation really illustrates well why typescript and type hinting in python are necessary to avoid errors. Thank you very much.
@ConceptandCoding
@ConceptandCoding Жыл бұрын
Thanks
@nitigya
@nitigya Жыл бұрын
This brings the point when to ditch Inheritance over Composition. Like how Abstraction/Inheritance brings coupling along with itself. Though, both Inheritance and Composition will have it's own pros/cons. Amazing playlist!
@CanadaKeBhai
@CanadaKeBhai Жыл бұрын
Best example of Liskov's substitution principle
@ConceptandCoding
@ConceptandCoding Жыл бұрын
Thank you
@rajugoud6465
@rajugoud6465 4 ай бұрын
This is the perfect Explanation of this principle, i watched this principle in paid courses, but this is the perfect explanation
@SushilChauhan-z1q
@SushilChauhan-z1q Ай бұрын
No one explained like you this solid concept..thanks
@aishwaryas8283
@aishwaryas8283 3 ай бұрын
The solution proposed seems to be similar to Interface Segregation principle with the only difference being we use classes here instead of interfaces for segregation. Thanks for the explanation.
@ashishgoswami6303
@ashishgoswami6303 Жыл бұрын
Awesome work ! I have been working for a while but you cleared concepts with examples!
@ConceptandCoding
@ConceptandCoding Жыл бұрын
Thanks
@saiakhil9206
@saiakhil9206 10 ай бұрын
I think there is a slight conceptual mistake in the start of the video. In the video, you mentioned that for a parent p, and child classes c1, c2, and c3, LSP says that parent *p = new c1should not break the behavior when c1 is replaced by c2, c1 is replaced by c3. However, my understanding is that for the same scenario, in a code, if you use c1_object.setSomething() or c2_object.setSomething() and if you have a parent object, the code should retain its behavior if you change c1_object with p1_object. Please correct my understanding if it's wrong.
@patel5532
@patel5532 10 ай бұрын
Bro by the way, Would like to study together LLD, HLD and DSA for interview? I'm also preparing for the google.
@saiakhil9206
@saiakhil9206 10 ай бұрын
Sure man@@patel5532
@AshishGusain17
@AshishGusain17 10 ай бұрын
It should be reverse......the code should retain its behaviour if you change p1_object with c1_object
@dpynsnyl
@dpynsnyl Жыл бұрын
very nice explanation! can you also add similar video explanation for all the other principles? This is a rock solid video, I don't think I will forget this easily.
@ConceptandCoding
@ConceptandCoding Жыл бұрын
Pls check the first video of this playlist
@pavanls2436
@pavanls2436 Жыл бұрын
One more thing that comes into mind is separation of behaviours. We can set up behaviors as interfaces and select class can implement that interface while the rest need not have to. (Learnt this through an example in Head First Design Patterns) Shreyansh Jain, correct me if I am wrong. With this, we don't have to create more classes.
@ConceptandCoding
@ConceptandCoding Жыл бұрын
Right that's interface segregation
@rohitvathumilli8176
@rohitvathumilli8176 Жыл бұрын
Hi Shrayansh, 1) The vehicle class, does it follow a single responsibility principle. 2) What if I return false instead of return null for the bicycle class, does it follow LSP
@paulputin
@paulputin Жыл бұрын
I assume that the method hasEngine() should be replaced with the method startEngine(). Then this tutorial will make sense.
@rohitvathumilli8176
@rohitvathumilli8176 Жыл бұрын
Thanks , can I know whether it follows single responsibility priciple
@pranaypaul6361
@pranaypaul6361 2 ай бұрын
So beautifully explained!
@SuyashD-cd9wr
@SuyashD-cd9wr 5 ай бұрын
Beautifully explained !!! keep up the good work !!!
@madmaxgaming5864
@madmaxgaming5864 9 сағат бұрын
great explanation.......
@shawkiahmed3586
@shawkiahmed3586 3 ай бұрын
Good example to understand. thanks for your efforts
@shubhammanecr7
@shubhammanecr7 10 ай бұрын
Amazing... thank you for such clear explanation!
@ConceptandCoding
@ConceptandCoding 10 ай бұрын
Thanks
@DhanyaGannavarapu
@DhanyaGannavarapu Жыл бұрын
Simple and clear Explanation
@dhirajshetty4317
@dhirajshetty4317 2 ай бұрын
Great explanation man!!
@iamkdblue
@iamkdblue 9 ай бұрын
How do we solve above problem? Last Mai toh wapas conflict ho Gaya ! Compiler error hai , solve kaise hoga wo ? Thanks for video aag laga diya hai 🔥
@shubhamagarwal1434
@shubhamagarwal1434 4 ай бұрын
Very well explained...awsome!!!
@gurupreetsingh8347
@gurupreetsingh8347 Жыл бұрын
In side bicycle u could return false instead of null ... Why returning null .. returning false can solve the problem..
@ConceptandCoding
@ConceptandCoding Жыл бұрын
Hi Gurupreet, i want to show the example. If Return type is Boolean, then returning null is also a valid. What i wanted to showcase that these kind of scenarios Liskov principles try to avoid. :)
@gurupreetsingh8347
@gurupreetsingh8347 Жыл бұрын
@@ConceptandCoding ok thanks
@beerboii2435
@beerboii2435 Жыл бұрын
In this case, I feel a better example would be to replace hasEngine with engineType in Vehicle class. For the case of bicycle, It would be logical to return null. So it would be better to understand why it is wrong to use that way.
@utsavkunal5221
@utsavkunal5221 8 ай бұрын
@@gurupreetsingh8347Just because implementation fits for that method doesn’t mean, we can have method. In Bicycle has per its behaviour there is not question of having engine, also if it is electricVehicle suppose, there you can return false.
@divijsharma5610
@divijsharma5610 8 ай бұрын
Instead you could have turnOnEngine like in SOLID video , Cycle cannot turn on engine.
@songsbooth1329
@songsbooth1329 7 ай бұрын
Superb explanation.👏👏
@rajeshdas2295
@rajeshdas2295 Жыл бұрын
Very Nice Bhaiya Got it properly!!!
@ConceptandCoding
@ConceptandCoding Жыл бұрын
Thank you
@codinghubfree
@codinghubfree 6 ай бұрын
since bicycle has not engine what if you return false since its return type is boolean. will it meet Liskov principle?
@ConceptandCoding
@ConceptandCoding 6 ай бұрын
i think i should name method little different which will make more sense. but in this example, return type is Boolean, so its a valid that NULL can be returned from this method, if it is returned, then it might break the existing code. That breaks Liskov principle
@CodeMode9313
@CodeMode9313 3 ай бұрын
thats a great explanation
@deepakmathur4218
@deepakmathur4218 Ай бұрын
Hi In your BiCycle method it is of type boolean and you are returning null ?
@nikhilgupta2569
@nikhilgupta2569 Жыл бұрын
Good explanation but probably the example could have been a little better for instance Bicycle's hasEngine method could simply return false in this case no need to return null. So this use-case of having Bicycle extending vehicle is not basically causing any trouble :)
@ConceptandCoding
@ConceptandCoding Жыл бұрын
Return type is Boolean, so null is a valid return type. Yes i think much better example can be used
@himanshukashyap1654
@himanshukashyap1654 9 ай бұрын
Can we get the slides that you are sharing in your videos?
@RealKaranVerse
@RealKaranVerse 18 күн бұрын
As hasEngine method return either true if engine is available and false if not available then in case of BiCycle you are returning null, shouldn't it be returning "false"?
@shashankcool
@shashankcool Жыл бұрын
Nicely explained with help of example 😊
@ConceptandCoding
@ConceptandCoding Жыл бұрын
Thank you
@arashrouhani-kalleh1797
@arashrouhani-kalleh1797 Жыл бұрын
Amazing solution!
@ConceptandCoding
@ConceptandCoding Жыл бұрын
Thank you
@paritoshdadhich2954
@paritoshdadhich2954 Жыл бұрын
Thank you so much for the wonderful explanations
@ConceptandCoding
@ConceptandCoding Жыл бұрын
Thanks
@tarunkundhiya5196
@tarunkundhiya5196 Жыл бұрын
Can we not return false for hasEngine in Bicycle? May be different example can be used getEngine() to show the problem. Nice explanation btw. I searched the internet most of them gives complex example without clearing much. PS: Instead of EngineVehicle we can rename MotorizedVehicle. just a thought.
@ConceptandCoding
@ConceptandCoding Жыл бұрын
yes, thats the example i wanted to showcase, but since its Boolean, null is the valid return value
@varunaggarwal7126
@varunaggarwal7126 Жыл бұрын
I think, Returning null is typically used when dealing with reference types, where a variable can hold a reference to an object or have no reference (null). However, for Boolean values, the options are limited to true or false to indicate the presence or absence of a certain condition. Please correct me!
@techlead_ashu
@techlead_ashu 2 ай бұрын
very good. thank you.👏👏👏👏
@charuagarwal8405
@charuagarwal8405 Жыл бұрын
Thanks for this video!
@ConceptandCoding
@ConceptandCoding Жыл бұрын
Thanks
@keshavmittal2844
@keshavmittal2844 Жыл бұрын
Very well explained
@ConceptandCoding
@ConceptandCoding Жыл бұрын
Thanks
@vallabhchugh2075
@vallabhchugh2075 Жыл бұрын
Great teaching. Do you have notes also ? that u can share
@mdrizwanahmed6746
@mdrizwanahmed6746 7 ай бұрын
great explanation
@Sp_Travel_Vlogs07
@Sp_Travel_Vlogs07 Жыл бұрын
Nice information brother 😊 keep sharing
@ConceptandCoding
@ConceptandCoding Жыл бұрын
Thank you
@renudeshmukh4608
@renudeshmukh4608 9 ай бұрын
Best Explanation
@ConceptandCoding
@ConceptandCoding 9 ай бұрын
thanks
@charuagarwal8405
@charuagarwal8405 Жыл бұрын
Very informative video!
@asramogal688
@asramogal688 Жыл бұрын
Hi , Even after all of the changes , in the 2nd case where Bicycle cant access hasEngine(),It still throws error right,How could we prevent this ?
@shivshaktipandey9993
@shivshaktipandey9993 Жыл бұрын
same question
@learnwithme7750
@learnwithme7750 9 ай бұрын
One question i.e I think we used multi-level inheritance to make sure that we follow strategy design pattern practises? please correct me if I am wrong.
@ConceptandCoding
@ConceptandCoding 9 ай бұрын
sorry i could not understand the relation between multi-level and strategy pattern, could you pls elaborate.
@learnwithme7750
@learnwithme7750 9 ай бұрын
@@ConceptandCoding sorry i think i got it wrong, thanks for addressing
@stepswithvishnu2924
@stepswithvishnu2924 10 ай бұрын
You could have return false in place of null in case of Bicycle's hasEngine() method?
@ConceptandCoding
@ConceptandCoding 10 ай бұрын
I could, but since the return type of method is 'Boolean' and null can also be returned, so that's a possible usecase. But yes I could have used some better method name.
@arashrouhani-kalleh1797
@arashrouhani-kalleh1797 Жыл бұрын
Fantastic 😍!
@ConceptandCoding
@ConceptandCoding Жыл бұрын
Thanks
@himanshushekhar2929
@himanshushekhar2929 2 ай бұрын
Shrayansh Sir, please share the slides link.
@tamonashchakrabarti7909
@tamonashchakrabarti7909 Жыл бұрын
Very good explanation indeed
@ConceptandCoding
@ConceptandCoding Жыл бұрын
thank you
@JustForFunYTG
@JustForFunYTG Жыл бұрын
Why bikecycle returned NULL instead of false for hasEngines()?
@ConceptandCoding
@ConceptandCoding Жыл бұрын
I wanted to give an example, since method return type is Boolean (object), Null is a valid return value.
@learner5358
@learner5358 Жыл бұрын
Will the problem arise if we have primitive boolean instead of Wrapper object Boolean and return false ? If we return false then it will follow the Liskov's substitution principle right ?
@vaibhavkhairnar7313
@vaibhavkhairnar7313 Жыл бұрын
very nice explanation
@ConceptandCoding
@ConceptandCoding Жыл бұрын
Thanks
@luisgonzalez8877
@luisgonzalez8877 11 ай бұрын
So, solution for LSP is to use ISP? In other words, use a different principal ?
@shenth27
@shenth27 5 ай бұрын
I dont understand why you need to return null from hasEngine method in the Bicycle class. Shouldn't it just return false?
@ConceptandCoding
@ConceptandCoding 5 ай бұрын
return type is Boolean it can return null, but i agree method name i can take something else to explain it better
@ShubhamKumar-by4mu
@ShubhamKumar-by4mu 3 күн бұрын
I have joined via membership but still can’t get the access to the few videos. Somebody help me
@ConceptandCoding
@ConceptandCoding 3 күн бұрын
Could you pls check if you have the right membership level
@sachinphogat8822
@sachinphogat8822 4 ай бұрын
why to make different classes implementing interfaces. Why cant we have interface extending another inteface?
@samithanandasena6642
@samithanandasena6642 6 ай бұрын
good explanation
@rohanyadav7327
@rohanyadav7327 9 ай бұрын
Isn't this looking like similar to I in Solid - interface segregation You are segregating the interfaces based on their functionalities
@novascotia2015
@novascotia2015 Жыл бұрын
sir is this for freshers or for sed1, or sde 2. now i am working on my dsa.
@ConceptandCoding
@ConceptandCoding Жыл бұрын
LLD is asked for freshers too buddy
@doodo_1
@doodo_1 10 ай бұрын
can u give slides you are using in videos for reference
@Animesh-v6r
@Animesh-v6r 6 ай бұрын
What is the difference between L and I then. Does this mean I is the solution of L??
@ConceptandCoding
@ConceptandCoding 6 ай бұрын
While they address different concerns, Interface Segregation Principle (I) can be considered a solution to avoid violating Liskov Substitution Principle (L) by designing more cohesive interfaces.
@Animesh-v6r
@Animesh-v6r 6 ай бұрын
@@ConceptandCoding Got it, Thanks😄
@shinchannohara1097
@shinchannohara1097 Жыл бұрын
Why a boolean method returning NULL, Bicycle could have returned False instead
@ConceptandCoding
@ConceptandCoding Жыл бұрын
I wanted to show an example. Since it's a wrapper object, Null is a valid return type
@shinchannohara1097
@shinchannohara1097 Жыл бұрын
@@ConceptandCoding understood
@Harsh-Choudhary451
@Harsh-Choudhary451 2 ай бұрын
Where can i get lld notes
@MohdImran-uq5iv
@MohdImran-uq5iv 2 ай бұрын
bhai❣
@pradipbedre653
@pradipbedre653 Жыл бұрын
3:41 but why we are returning null we can return the false as well right.
@ConceptandCoding
@ConceptandCoding Жыл бұрын
Boolean is a wrapper class and null is also a valid value. So for example purpose i sent null.
@esportathlete4703
@esportathlete4703 2 ай бұрын
This is not really a satisfactory example.
@Dineshkumar-gr8nj
@Dineshkumar-gr8nj 29 күн бұрын
Agree with you. Generally the example should be in such a way that substitution doesn't change/break the existing implementation. Not introduce exception voluntarily.
@linuxadmin8027
@linuxadmin8027 Жыл бұрын
Thank you❤
@ConceptandCoding
@ConceptandCoding Жыл бұрын
Thanks
@rohitkumarsah77
@rohitkumarsah77 8 ай бұрын
why the bicycle is not returning false instead of null...this will not break the code.
@ConceptandCoding
@ConceptandCoding 8 ай бұрын
return type of the method is Boolean, so returning Null is a valid return type.i think method can be improved a bit
@akashchourasiya72
@akashchourasiya72 Жыл бұрын
isn't also interface segregation principle?
@ConceptandCoding
@ConceptandCoding Жыл бұрын
Similar, but intention is different, it tries to solve problem from code which uses interface. Interface segregation says we should not force child class to implement method which it font require. But Liskov days, if we swap with other child class, code should not break
@AmanDubey-b3q
@AmanDubey-b3q Жыл бұрын
Did you provide code and this file?
@Aman-ln9dx
@Aman-ln9dx 10 ай бұрын
If possible can u please provide notes ?
@raushansoni5383
@raushansoni5383 2 ай бұрын
Combine it in one shot sir
@AbhishekKumar-kk6qs
@AbhishekKumar-kk6qs Жыл бұрын
Hi Shreyansh, So the solution is strategy design pattern , am i right ?
@ConceptandCoding
@ConceptandCoding Жыл бұрын
:) no Abhishek, i would say, interface segregation generally solves this
@chandrikasaha6301
@chandrikasaha6301 Жыл бұрын
sir if you could share a git link. I am trying these in python
@ConceptandCoding
@ConceptandCoding Жыл бұрын
Sure will add
@snowleopard3925
@snowleopard3925 7 ай бұрын
bro can I get the pdf of these notes?
@Jock3R87
@Jock3R87 Жыл бұрын
In bicycle class you are returning nil ideally it should return false.. i guess this is not the correct example
@ConceptandCoding
@ConceptandCoding Жыл бұрын
Return type is Boolean, null is a valid return value.
@Jock3R87
@Jock3R87 Жыл бұрын
@@ConceptandCoding in any of the programming language Bool is not have null value mate.. Its either True/ False otherwise the whole meaning of Bool is wasted
@ConceptandCoding
@ConceptandCoding Жыл бұрын
@@Jock3R87 welcome to Java world buddy, it's a wrapper object and null is valid value for it. Yes generally it make sense to return only true false but since we define the return type as Boolean object not the primitive one boolean. , Null can be passed. Hope this clarifies
@sreelekshmiraj6424
@sreelekshmiraj6424 Жыл бұрын
Could you please provide the codes or notes pdf
@ConceptandCoding
@ConceptandCoding Жыл бұрын
Sure will add soon
@Aman-ln9dx
@Aman-ln9dx 10 ай бұрын
Your slide
2. Strategy Design Pattern explanation | LLD System Design #1  | Design pattern explanation in Java
17:26
啊?就这么水灵灵的穿上了?
00:18
一航1
Рет қаралды 66 МЛН
小天使和小丑太会演了!#小丑#天使#家庭#搞笑
00:25
家庭搞笑日记
Рет қаралды 60 МЛН
SOLID Design Principles in java with Example | JavaTechie
34:44
Java Techie
Рет қаралды 193 М.
Learn SOLID Principles with CLEAN CODE Examples
28:35
Amigoscode
Рет қаралды 275 М.
This is the Only Right Way to Write React clean-code - SOLID
18:23
Liskov's Substitution Principle | SOLID Design Principles (ep 1 part 1)
16:08
Christopher Okhravi
Рет қаралды 159 М.
SOLID  Principal - Interview Questions and Answers
24:04
Interview Happy
Рет қаралды 115 М.
SOLID Principles: Do You Really Understand Them?
7:04
Alex Hyett
Рет қаралды 189 М.
Liskov Substitution Principle
20:16
Christopher Okhravi
Рет қаралды 13 М.