Liskov Substitution Principle Explained - SOLID Design Principles

  Рет қаралды 119,563

Web Dev Simplified

Web Dev Simplified

4 жыл бұрын

Writing clean code is tough, and is one of the largest differences between junior and senior developers. One way that you can quickly improve your code and start writing well designed code now is to implement the Liskov substitution principle. This principle is part of the SOLID design principles and is, in my opinion, the most important rule of SOLID for object oriented programming.
The main idea of the Liskov substitution principle is that any function/module that interacts with a class should also be able to interact with all subclasses of that class without breaking. This essentially means that a class is interchangeable with its subclasses.
Most likely you have written tons of code in violation of this principle, I know I have, but hopefully this video will help introduce you to why this principle is so good at making your code clean and maintainable.
🧠 Concepts Covered:
- What the Liskov substitution principle is
- Why the Liskov substitution principle is important
- How to use the Liskov substitution principle
- How to spot violations of the Liskov substitution principle
🌎 Find Me Here:
My Blog: blog.webdevsimplified.com
My Courses: courses.webdevsimplified.com
Patreon: / webdevsimplified
Twitter: / devsimplified
Discord: / discord
GitHub: github.com/WebDevSimplified
CodePen: codepen.io/WebDevSimplified
#SOLID #WDS #LiskovSubstituionPriniciple

Пікірлер: 200
@WebDevSimplified
@WebDevSimplified 4 жыл бұрын
As requested here is the composition vs inheritance video: kzbin.info/www/bejne/pJ_adWiCrNykmtE
@NoahNobody
@NoahNobody 2 жыл бұрын
You should add this to the Design patterns playlist.
Жыл бұрын
Thank you senpai
@MrPogi-lf5gz
@MrPogi-lf5gz 4 жыл бұрын
Yes to composition vs inheritance video!
@aniceguy2577
@aniceguy2577 4 жыл бұрын
Up
@armaandhanji2112
@armaandhanji2112 4 жыл бұрын
Double yes to composition vs inheritance
@fernandobalino9519
@fernandobalino9519 4 жыл бұрын
I didn’t realize you could be a great programmer, a fantastic teacher, AND a supermodel at the same time. Great video.
@baphnie
@baphnie 3 жыл бұрын
rofl true tho
@sabrinakingsley798
@sabrinakingsley798 3 жыл бұрын
Maybe don't objectify the guy.
@liquidsnake6879
@liquidsnake6879 3 жыл бұрын
@@sabrinakingsley798 Jeez, here come the witch burners lol excuse us while we all go poke out our eyes to appease your social sensibilities
@fernandobalino9519
@fernandobalino9519 3 жыл бұрын
@@sabrinakingsley798 Objectification involves treating the person purely as an object, which is not what I did. I wrote that he was a great programmer and a fantastic teacher. He also happens to be very handsome, which I mentioned. Had I only written something like "you're hot," I'd understand your comment, but it's not what was written.
@sabrinakingsley798
@sabrinakingsley798 3 жыл бұрын
@@fernandobalino9519 Yeah, your format was compliment, compliment, AND objectification.
@majicboca4784
@majicboca4784 4 жыл бұрын
Kyle, your approach to explaining these abstract, seemingly obscure principles and concepts with simple examples, is brilliant. So instead of approaching dry and abstract concepts from the top down with professorial lectures of principles that need to be understood, your bottom up approach with spot-on examples illuminate the subject matter. I have noticed how your subscriber base has been deservedly growing, and it is because of your clarity in presenting these topics and the relatively short videos that make it digestible. I wish you much continued success and look forward to your new videos. Best always.
@phogbinh
@phogbinh 4 жыл бұрын
Thank you for simplifying the Liskov principle for all of us with easy-to-comprehend examples. Keep up the good work!
@muhammadumair7861
@muhammadumair7861 4 жыл бұрын
You are such a great instructor ! Finally I understand all about SOLID in just couple of minutes.
@rishabhkalra9505
@rishabhkalra9505 4 жыл бұрын
Okay... This is probably the first time i understood liskov. Thanks a lot man and yea i think you should make videos on composition and aggregation too... Overall your content for solid is pretty solid 🎉👌
@reactdejv5562
@reactdejv5562 4 жыл бұрын
I love these SOLID principles series, nicely done man!
@joshvanriel5176
@joshvanriel5176 Жыл бұрын
You are the dom perignon of online JS educators. Clear, concise and well structured! Thanks very much for your content 🙌🏻
@puspamadak
@puspamadak 3 жыл бұрын
I had never understood the concepts of OOP in my school classes. Your explanations are very easy to understand!
@maharun
@maharun Жыл бұрын
Thanks a bunch. Found your video while searching about "Why is it not allowed to narrow down scope of a method while overriding?" and also why the developers choose to do so. It makes sense now. Thanks for making these topics so easy to understand.
@MrPauld123456
@MrPauld123456 3 жыл бұрын
Thank you. As an amateur coder you have taught me tons. Thank you. Love your videos.
@PhilHawkshaw
@PhilHawkshaw 4 жыл бұрын
I’m just starting out on programming and these design videos are fantastic for understanding the principles easily from the beginning of my journey. YES for Composition please :-)
@rapha5210
@rapha5210 4 жыл бұрын
Uauh. I've programmed since 2000s (vb6, turbo Pascal, etc) and I still enjoy each one of your videos! Good job!
@ShujathHussain0
@ShujathHussain0 4 жыл бұрын
Congrats on 100K!!! and great explanation.
@robbiew4534
@robbiew4534 4 жыл бұрын
I appreciate your channel. This is excellent content for people reviewing for job interviews.
@desarrollojava
@desarrollojava 3 жыл бұрын
And another very clear, clever and successful teaching video. Thank you!
@bishopshawiii7292
@bishopshawiii7292 4 жыл бұрын
Finally a simple explanation of the solid principles....👍 for composition vs. Inheritance
@suefengtan6141
@suefengtan6141 4 жыл бұрын
I love your videos so much Kyle! I had trouble understanding the SOLID Principles before, and your videos are so helpful for gaining understanding!
@WebDevSimplified
@WebDevSimplified 4 жыл бұрын
I'm glad I could help!
@akn9699
@akn9699 4 жыл бұрын
A Solid Video Concept from THE MAN - " Kyle WDS " ! We love you man and happy holidays !
@hyfydistro
@hyfydistro 3 жыл бұрын
The bird inheritance example was so cute. Your explanations are easy to follow. You are such a great teacher. 😁👍
@jackhaugh4198
@jackhaugh4198 2 жыл бұрын
I've read the whole clean code book by Uncle Bob and still didn't understand these SOLID principles as much as until your 10 minute video. Thanks!
@KnightToD5
@KnightToD5 4 ай бұрын
Great series on the SOLID principles. Your content is fantastic.
@Shinbo2
@Shinbo2 4 жыл бұрын
Hands down best coding channel on KZbin. Many thanks and keep em coming!
@patrickmcauliffe7162
@patrickmcauliffe7162 3 жыл бұрын
love you videos my man! I started a course and i'm already way ahead of the knowledge provided so using your vids to keep that momentum. I want some WDS merch! I'm thinking beanies, bum bags and night pants!
@brecoldyls
@brecoldyls 4 жыл бұрын
I never heard of Liskov before, but this makes so much sense! Also Kyle, could you please actually make a video on composition?? A few weeks ago I was trying to write a small game engine in JavaScript, and I ran into the exact problem you were describing when I tried to make a class for objects that could be movable, drawable to the screen, and have behavior states. I eventually ended up using composition similar to how unity game objects work, but I’m not sure if I still fully grasp the concept. Thank you!
@kurykuryk
@kurykuryk 4 жыл бұрын
Thumbs up!!!Waiting for composition
@PortEXE
@PortEXE 3 жыл бұрын
This was the most confusing one to me. I read several definitions before I finally decided to see what Kyle had to say about it. Good job!
@river6634
@river6634 3 жыл бұрын
Excellent video. Concise and to the point. Very helpful.
@philhagerman
@philhagerman 4 жыл бұрын
Dude first, CONGRATS ON 100k subs!!!! You earned it man. Second, yes please do composition with JavaScript
@kamuizero
@kamuizero 4 жыл бұрын
So clear and easy to understand, thank you!
@mj65535
@mj65535 3 ай бұрын
This is an interview question I used to ask devs.. Btw, between square inherits rect or rect inherits square, always inherit rect from square, as you are adding a paramater, a second size dimension. Square has sideLength. Rectangle has a second sid legnth. Things get a lot cleaner following that.
@whoman7930
@whoman7930 4 жыл бұрын
Thanks Sir, for everything you putting efforts and what you are doing for us! . And I challenge you to make a tutorial on any board game, like chess, checkers, carrom etc. Anything you can make with js. But must be a board game.
@GeoffreyReemer
@GeoffreyReemer 4 жыл бұрын
I'd love to sign up for Composition, too. And for more videos about the various birds in this world 🙂.
@coolcha
@coolcha 4 жыл бұрын
Love your videos on SOLID and I want to see a video of compositiion vs inheritence video.
@shgysk8zer0
@shgysk8zer0 3 жыл бұрын
That's one of the things I really like about PHP. You get interfaces and abstract classes and traits.
@davidduvernay7302
@davidduvernay7302 4 жыл бұрын
I was craving for some good explanation about Liskov substitution. Thanks you very much! PS: can't wait for I on SOLID.
@MrMarkgyuro
@MrMarkgyuro 4 жыл бұрын
i would like to hear from function compositions advantages! : ) Great video! :)
@jeremiahperdue5518
@jeremiahperdue5518 4 ай бұрын
Wow amazing explanation, this is the first time I've been able to understand this principle. Although I should add that nowadays in python classes can inherit from multiple classes so that sort of sidesteps that issue
@shayama
@shayama Жыл бұрын
These expalmes are everywhere, really programmers cannot find more intresting expalmes...
@ayushraj-zb6sv
@ayushraj-zb6sv 3 жыл бұрын
I used to think I write good programs, but after learning SOLID principles I realized why I am getting all those rejections! Thank you Kyle for such awesome content. chhers!
@y7amdy
@y7amdy 3 жыл бұрын
Your videos are awesome! would've loved it, if you could provide us with the src code as you did with the design patterns videos
@archiee1337
@archiee1337 Жыл бұрын
The best content for SOLID on the Internet.
@marcbarbier5646
@marcbarbier5646 3 жыл бұрын
thanks a lot i have exams tomorow and you just saved my day with thoses clear explaination
@k1z1eMe01
@k1z1eMe01 3 жыл бұрын
Great explanation. Thank you, I'm satisfied.
@davivify
@davivify 2 жыл бұрын
Sounds like polymorphism to me. I've used polymorism twice to very good avail. Once in an undo/redo (stack based) system and once in a linked list of tokens. And all I can say is Thank God for it. And one thing I love about it is how it allows for future expansion. If I should add new token types or undo/redo types on the future, no sweat. I don't have to change a thing in either my containers or my base classes. I could even distribute the code as a library and never worry about users needing to change the base code.
@stith_pragya
@stith_pragya 5 ай бұрын
Thank You So Much for this wonderful video........🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻
@wjsilva85
@wjsilva85 Жыл бұрын
Thank you man. Awesome class.
@PlayRiteProductions
@PlayRiteProductions 4 жыл бұрын
More on composition please. Thanks man
@vlads7774
@vlads7774 Жыл бұрын
excellent explanation , thanks
@dmxd
@dmxd 4 жыл бұрын
Yes for composition
@sathishraj1
@sathishraj1 3 жыл бұрын
You know, I never learnt anymuch from anyother channels.. Just awesome , u r making programming fun and interesting .. But one drawback, after watching your contents, I can not spend my time in other channels
@Dylen
@Dylen Жыл бұрын
In the modern world, we only need one guy to explain it better than our teachers to kick the exam in the nuts
@vladimirdoktorov1511
@vladimirdoktorov1511 4 жыл бұрын
Gratz for 100k
@sergeykas90
@sergeykas90 4 жыл бұрын
Thank you for the great explanation. Are you planning to continue this series? Or maybe doing series about design patterns like this?
@WebDevSimplified
@WebDevSimplified 4 жыл бұрын
I have a few videos in this series already uploaded and a few videos in a design patterns series as well that you can check out.
@munapadhi8723
@munapadhi8723 4 жыл бұрын
Best tutorials...... I love ur all videos
@jakubczechowski1159
@jakubczechowski1159 3 жыл бұрын
Thank you for the video.
@sonoftroy8572
@sonoftroy8572 4 жыл бұрын
this is off topic, but the lighting for your KZbin setup is made the video quality way better!!! so nice going
@WebDevSimplified
@WebDevSimplified 4 жыл бұрын
Thank you!
@md.akib5124
@md.akib5124 4 жыл бұрын
love this series
@milanlucansky2825
@milanlucansky2825 4 жыл бұрын
Yes, please do composition video.
@himanshukarnwal880
@himanshukarnwal880 4 жыл бұрын
Yes please share the video on composition
@niteesh__mishra
@niteesh__mishra 4 жыл бұрын
Thanks Kyle 👏
@CapiEtheriel
@CapiEtheriel 3 жыл бұрын
I kind of feel the bird issue is actually an interface issue. Like, it should not ask duck.fly(), but rather duck.go(). And penguin.go(). Now, whether the bird flies or swims is the bird's class concern. Client code just needs a fixed, reliable interface. And that's what Liskov Substitution Principle is about.
@alexanderamante9028
@alexanderamante9028 2 жыл бұрын
I totally agree. this will be fixed with an interface instead of creating 2 separate super class of different birds(e.g flyingBird and swimming bird).. it just like all birds can move but move differently is what the essence of liskov substitution principle is about
@artem_zakharchuk
@artem_zakharchuk Жыл бұрын
I'm from UA...looking for several hours articles which can explain me this moskovian guy principle) thank you - I got it everything) even with my low english level!)
@nilen
@nilen 2 жыл бұрын
Thank you brotha!
@djr2123
@djr2123 4 жыл бұрын
Yes composition video please!!
@samdimahmood9047
@samdimahmood9047 4 жыл бұрын
Yes to composition vs inheritance video!!!
@Bomba2494
@Bomba2494 4 жыл бұрын
Way better then my uni bro ty ♥
@oanacristea2572
@oanacristea2572 2 жыл бұрын
thank you!!
@lindawisebear
@lindawisebear 3 жыл бұрын
The bird method made LSP click; great example!!
@ridl27
@ridl27 4 жыл бұрын
you are cool bro. thx for all of your videos
@zoecarlibur
@zoecarlibur Жыл бұрын
Hey, Thanks for the video, Your examples and explanations are very precise and clear. Can I suggest you create a Udemy account for your courses? It would be easier to find and keep track of since a lot of people learn using that platform.
@solar679
@solar679 3 жыл бұрын
Great Video Fam.
@ManontheBroadcast
@ManontheBroadcast 4 жыл бұрын
+1 for composition over inheritance ...
@InvincibleMan99
@InvincibleMan99 4 жыл бұрын
nice explanation. Good voice
@usama57926
@usama57926 4 жыл бұрын
yes sir pls make video on composition
@vinceramcesoliveros6739
@vinceramcesoliveros6739 4 жыл бұрын
How to have method overloading in JavaScript. 2 same function name with different parameters.
@pierantoniodurante3892
@pierantoniodurante3892 2 жыл бұрын
thank u very much !!!!!!
@knightmarerip711
@knightmarerip711 2 жыл бұрын
Implementing the Liskov principle in JS is a challenge compared to C# mainly because JS does not have the concept of interfaces. So implementing this is more of a personal discipline. I'm not against JS. I look at it as a wild language. Still this is a great explanation on how to clean up code!
@DrewSorensenMusic
@DrewSorensenMusic 4 ай бұрын
Thinking as you’re talking. I wonder if the issue is with trying to inherit actions, which can change. If the birds inherited Wings (the object) instead of Flying (the action), then, Pigeon Wings can fly. Penguin wings can swim. And Duck wings can fly. Ducks swim with their feet. So the feet objects for Ducks can walk and/or swim. Inheritance can save a lot of time. So inheriting correctly is probably the right answer to the problem.
@akashvijayasarathy6234
@akashvijayasarathy6234 Жыл бұрын
if a class can't inherit multiple concrete classes cant we use interfaces like in this case IflyingBird and IswimmingBird interfaces and the bird can implement both interfaces?
@satyadeeproat2012
@satyadeeproat2012 3 жыл бұрын
Woah. that just blew my mind
@je9625
@je9625 4 жыл бұрын
Two thumbs up Kyle.
@thalibmuhammad9519
@thalibmuhammad9519 2 жыл бұрын
so, can i say that overriding method with other function = violiates liskov principle?
@shynggyskassen942
@shynggyskassen942 3 жыл бұрын
GREAT VIDEOS!!!!!!!!!!!!!!
@av03
@av03 4 жыл бұрын
Let's go for composition
@yettodecideahandle
@yettodecideahandle 3 жыл бұрын
You're the best.
@firewatermoonsun
@firewatermoonsun 11 ай бұрын
In other words, in React, child component's props should source entirely from parent component's props?
@rohans5265
@rohans5265 4 жыл бұрын
Thanks for the video! Can't you create interfaces and perform multiple inheritance using interfaces? That is another solution to the problem along with composition
@ExtraTurtle
@ExtraTurtle Жыл бұрын
The second part is a way to understand this simply, the first part is a way to understand that sometimes, your code might not pass the liskov principle and you might not see it that simply like in the second part.
@kevinfriedman6766
@kevinfriedman6766 4 жыл бұрын
Great video as always! Yes please, I’d love to see a video about composition vs inheritance. Awesome content!!
@user-zt1hx3ci2v
@user-zt1hx3ci2v 3 жыл бұрын
Do mixins solve inheritance problem here?
@EdwardSelig
@EdwardSelig Жыл бұрын
To solve the problem of making a flyingSwimingBird without composition if you're using a language like PHP that supports classes implementing multiple interfaces can't you make a Duck that implements a FlyingBird Interface and a SwimmingBird Interface?
@tushar54983
@tushar54983 Жыл бұрын
@WebDevSimplified I may be wrong but I find the explanation little bit wrong. Taking the bird example, Liskov Substitution Principle (LSV) is not violated if say Penguin and Duck's fly() behave differently, meaning duck's instance fly() will say "I can fly" and penguin's instance fly() will error out saying "Cannot fly". This is what Polymorphism is, different class instances behaving differently on calling the same function. LSV states that "if a function takes an instance of a class, the same function should be able to take an instance of derived class from that class and the functionality of that function should not break". LSV would be violated if say Penguin class implements a function called penguinFly() that will error out saying "Cannot fly" but does not implement fly(). So now the client, meaning the user of the Penguin instance has to know that it has to call penguinFly() to get correct functionality because if we call penguin's instance fly(), it will say "I can fly" which is not correct behavior and now LSV is violated.
@nowieszco868
@nowieszco868 4 жыл бұрын
What about to create Bird class, then subclassess: FlyingBird and SwimmingBird. And the class Duck that extends from Bird? Wont we have then functionality of both: flying and swimming bird?
@LinkChenTW
@LinkChenTW 4 жыл бұрын
The first question I google for this tutorial is "does penguin fly"...lol By the way, nice job!
@MECHAJAYKUMARR
@MECHAJAYKUMARR 2 жыл бұрын
Kindly make the video for oops concept in js
@MI982
@MI982 3 жыл бұрын
For some reason, this reminded my of Strategy pattern.
@zerobit778
@zerobit778 Жыл бұрын
I think one problem with the polymorphism is that the type could not be inferred dynamically. If we declare the object like Rect rec = new Square() Then the rec can only be recognized as Square in the lifetime of the object. In that case it is fixed, which is different like real world (Start shape is square, but as we elongate the side it could be transformed to Rect).
@TheWordBecameFleshJ114
@TheWordBecameFleshJ114 Жыл бұрын
Liskov Substitution Principle can be called Base Class Segregation Principle as well. :D
Interface Segregation Principle Explained - SOLID Design Principles
8:20
Web Dev Simplified
Рет қаралды 102 М.
Dependency Inversion Principle Explained - SOLID Design Principles
13:00
Web Dev Simplified
Рет қаралды 153 М.
Eccentric clown jack #short #angel #clown
00:33
Super Beauty team
Рет қаралды 20 МЛН
СҰЛТАН СҮЛЕЙМАНДАР | bayGUYS
24:46
bayGUYS
Рет қаралды 734 М.
когда достали одноклассники!
00:49
БРУНО
Рет қаралды 2,5 МЛН
Composition Vs Inheritance - Why You Should Stop Using Inheritance
10:16
Web Dev Simplified
Рет қаралды 171 М.
Open/Closed Principle Explained - SOLID Design Principles
10:22
Web Dev Simplified
Рет қаралды 132 М.
Liskov's Substitution Principle | SOLID Design Principles (ep 1 part 1)
16:08
Christopher Okhravi
Рет қаралды 157 М.
Liskov: The Liskov Substitution Principle
4:23
Turing Awardee Clips
Рет қаралды 17 М.
Single Responsibility Principle Explained - SOLID Design Principles
6:17
Web Dev Simplified
Рет қаралды 183 М.
8 Design Patterns EVERY Developer Should Know
9:47
NeetCode
Рет қаралды 993 М.
Eccentric clown jack #short #angel #clown
00:33
Super Beauty team
Рет қаралды 20 МЛН