SOLID Principles: Do You Really Understand Them?

  Рет қаралды 108,965

Alex Hyett

Alex Hyett

Күн бұрын

People mention SOLID everywhere but very few do a good job of explaining it. I am hoping to put an end to that in this video so you can once and for all understand all the SOLID principles.
Learn the SOLID principles in depth in my new course: dometrain.com/course/from-zer...
☕️ I don’t accept paid sponsorships and I have turned off mid-video ads. You’re welcome! If you would like to support my channel see: ko-fi.com/alexhyett
📨 Join my free weekly newsletter for advice, technology and more: newsletter.alexhyett.com
🗺️ Backend Developer Roadmap: www.alexhyett.com/backend-dev...
📝 Read me instead: www.alexhyett.com/solid-princ...
🎓 RECOMMENDED COURSES (Use code FRIENDS10 for 10% off)
The Complete Web Developer Course - academy.zerotomastery.io/a/af...
The Complete Junior to Senior Web Developer Roadmap - academy.zerotomastery.io/a/af...
C#/.NET Bootcamp: The Fundamentals: academy.zerotomastery.io/a/af...
Complete SQL + Databases Bootcamp - academy.zerotomastery.io/a/af...
📚 RECOMMENDED BOOKS
Clean Code - geni.us/5AEwj2
Design Patterns - geni.us/5ncUt
Developer Hegemony - geni.us/lAXy
Pragmatic Programmer - geni.us/GfNj9
Data Structures and Algorithms Made Easy - geni.us/sqg6kJ
Refactoring - geni.us/ufAP0mE
Pragmatic Thinking and Learning - geni.us/x81A
⏳ TIMESTAMPS
00:00 - Introduction
00:30 - Single Responsibility Principle
01:51 - Open-Closed Principle
02:33 - Decorator Pattern
03:02 - Extension Methods
03:39 - Liskov Substitution Principle
04:18 - Interface Segregation Principle
05:11 - Dependency Inversion Principle
06:37 - Conclusion
🧑🏻‍💻 You can check out more of my favourite tools on my website: www.alexhyett.com/tech/
🔗 MY KEY LINKS
🌍 Blog - www.alexhyett.com/
🐘 Mastodon - social.alexhyett.com/@alex
🧑‍💻 WHO AM I
I’m Alex, a Software Developer and KZbin working in the UK. I make videos about software development to help developers with the skills they need to be senior developers. As well as this KZbin Channel, I also write articles on my website (alexhyett.com) and write a regular newsletter that contains some thoughts to help aspiring developers.
‼️ DISCLAIMERS
Some of the links in this description are affiliate links, for which I get a small commission, at no extra cost to you 🙂. I appreciate you supporting my channel so I can continue providing you with free software development content!
#coding #programming #developer

Пікірлер: 118
@andrewmarshall195
@andrewmarshall195 8 ай бұрын
This is totally brillant....short and concise and really understandable! Top class this!
@alexhyettdev
@alexhyettdev 8 ай бұрын
Thank you Andrew!
@hyperborean72
@hyperborean72 2 ай бұрын
Finally I understood all of the SOLID principles. Thank you a lot
@elvikingo
@elvikingo 3 ай бұрын
This is good. I'm glad you explained the huge benefit of interfaces at the end: makes everything testable. Code covered by tests can be modified and refactored safely, which makes the code easier to maintain in the long run (the purpose of good design).
@victorialacerda6919
@victorialacerda6919 8 ай бұрын
Just came here to say hello from brazil! I've started moving careers to data science and your videos are so well written and the content so well explained that I've been binge watching them! thank you for posting.
@alexhyettdev
@alexhyettdev 8 ай бұрын
That’s awesome thank you!
@dos328
@dos328 3 ай бұрын
This has been by far the best video explaining SOLID Thank you so much! I love the stack and heap memory video too. Keep it up!
@alexhyettdev
@alexhyettdev 3 ай бұрын
Thank you!
@sebon11
@sebon11 11 ай бұрын
Thanks for the video dude, rly great explanation!
@alexhyettdev
@alexhyettdev 11 ай бұрын
Thank you! I am glad you liked it.
@perisicnikola37
@perisicnikola37 3 ай бұрын
The best tutorial about OOP I have seen so far. Thank you Alex! Also these animations are awesome
@alexhyettdev
@alexhyettdev 3 ай бұрын
Wow, thanks! I am glad you like the animations.
@ognjenvojnovic9778
@ognjenvojnovic9778 6 күн бұрын
Hi Alex. This was brilliant, and in only 7 minutes. Thanks man
@mattedge333
@mattedge333 3 ай бұрын
Clear, succinct, snappy. A really nice refresher. Thank you
@alexhyettdev
@alexhyettdev 3 ай бұрын
You're very welcome! Thanks for commenting!
@AlexKashie
@AlexKashie 5 ай бұрын
Brilliantly elaborated... Thank you Alex!
@alexhyettdev
@alexhyettdev 5 ай бұрын
You’re welcome!
@tom111_14
@tom111_14 16 күн бұрын
clear and amazing ! thanks a lot Sir !
@punkerIII
@punkerIII 11 ай бұрын
Thank you for your content!
@alexhyettdev
@alexhyettdev 11 ай бұрын
You’re welcome! Thank you for leaving a comment!
@smileoez
@smileoez 8 ай бұрын
Thank you very much it helped a lot to comprehend sense of all of principles
@alexhyettdev
@alexhyettdev 7 ай бұрын
You're welcome! I am glad it was helpful
@reppair
@reppair Ай бұрын
I've herd these explained by many people. Yours amongst the cleanest and simplest, also shortest. All these making for a top-notch explanation. :)
@alexhyettdev
@alexhyettdev Ай бұрын
Thank you! I don't like to waffle.
@MenziManqele
@MenziManqele 28 күн бұрын
Super nice and easy to grasp. Thank you.
@jurkocharczenko4581
@jurkocharczenko4581 3 ай бұрын
Best video about SOLID principles for OOD (OOP)
@hamaed19
@hamaed19 11 ай бұрын
Very useful content, Keep it up 👍
@alexhyettdev
@alexhyettdev 11 ай бұрын
Thanks, will do!
@togofar
@togofar 5 ай бұрын
I wouldn't say that the SOLID principles are too vague to be useful but I do agree that they are very abstract. I've come across many developers who know what the principles say but they don't really use them because they don't know when they should be using them or how to translate them into code. Maybe we need a set of more concrete principles to fill that gap.
@fludeo1307
@fludeo1307 4 ай бұрын
I jumped from game dev to web dev and I can say, I never meet any web dev that actually has the criteria to apply the principles. It's funny because they can recite the principles well, but then the code is never abstracted. They always 'just add another serivce.'
@leezhenjian7451
@leezhenjian7451 16 күн бұрын
Beginner here, thank you for dumbing it down for me to understand!
@sameerarasanga8975
@sameerarasanga8975 2 ай бұрын
Great explanation , within just 7 minutes !!!!
@NoahNobody
@NoahNobody 10 ай бұрын
Great work. I took hours to read about these 5, barely learned them, then promptly for got them a little while after. It all came back super quick and I think I learned them much better after watching this video.
@alexhyettdev
@alexhyettdev 9 ай бұрын
Thank you, I am glad it helped as refresher.
@alanchen4257
@alanchen4257 4 ай бұрын
Clear & Concise !!
@craftedbysrs
@craftedbysrs 3 күн бұрын
You are an Amazing tutor!
@emhyrvemrais7574
@emhyrvemrais7574 Ай бұрын
Very good explanation i understood everything great video.
@dralps
@dralps 10 ай бұрын
One of the best explanations of the SOLID principles!
@alexhyettdev
@alexhyettdev 10 ай бұрын
Thank you!
@petiks6391
@petiks6391 8 ай бұрын
You missed the opportunity to say solid explanation!
@hristopisarev1827
@hristopisarev1827 8 ай бұрын
The best explanation I ever heard. Man, you are great! Keep up the great work 👏.
@alexhyettdev
@alexhyettdev 8 ай бұрын
Thank you! 👍👍
@sobit0ks
@sobit0ks 4 ай бұрын
Easiest LSP explanation ever. Thank you.
@alexhyettdev
@alexhyettdev 4 ай бұрын
Glad it helped! Thanks for commenting!
@dmytrodanko8592
@dmytrodanko8592 3 ай бұрын
It's very very very understandable. The example with child-parent-human is very smart and simple )
@sharadregoti7742
@sharadregoti7742 9 ай бұрын
Bro, You got teaching skills. Nice!!!
@alexhyettdev
@alexhyettdev 9 ай бұрын
Thank you! I try my best!
@bubumimo
@bubumimo 7 ай бұрын
Your conclusion is absolute important.
@alexhyettdev
@alexhyettdev 7 ай бұрын
100%, SOLID isn't going to fix bad code, and it is easy to write good code without using SOLID. Thanks for commenting :)
@simonslater7257
@simonslater7257 5 ай бұрын
Please cover CUPID, this was a really good talk and I'd love to see this through the CUPID lens :). I've just seen the "CUPID for joyful programming" talk and really liked it, thank you for that recommendation!
@alexhyettdev
@alexhyettdev 5 ай бұрын
Will do! It’s on the list
@user-wk1tl7vf1n
@user-wk1tl7vf1n Ай бұрын
very clear explanations
@marna_li
@marna_li 7 ай бұрын
Extension methods are the closest thing that C# has to traits. Hopefully, we will have more universal extension in an upcoming version, as Mad Torgersen and Dustin Campbell demonstrated at Build 2023. But still, if you are looking for changing behavior at runtime, then the decorator pattern is the one. Btw. Forwarding stuff to another class is an example of indirection. One should be careful of that. Not to do it just because.
@_mubir
@_mubir 8 ай бұрын
nice && concise.carry on.
@alexhyettdev
@alexhyettdev 8 ай бұрын
Thank you!
@_mubir
@_mubir 8 ай бұрын
@@alexhyettdev Just for clarification to achieve "S" its better to divide interface by feature of my app. like: - generating pdf (all methods for generating pdf would be in the interface) or - say like for one for sending event & another for consuming event in event base architecture. !!
@khalidelgazzar
@khalidelgazzar 4 ай бұрын
Great video .. thank you 😊
@alexhyettdev
@alexhyettdev 4 ай бұрын
You’re welcome 😊
@takatakboy
@takatakboy 8 ай бұрын
That BTTF display at the back was so distracting cause it makes me want to buy one and I couldnt stop staring at how cool it is!
@alexhyettdev
@alexhyettdev 8 ай бұрын
My wife bought me that. It is awesome. It is just a light, I wish it was a working clock. I may have to make one at some point...
@korniszon68
@korniszon68 8 ай бұрын
We actually have a dude in our project that brought this SOLID up to a single line. Explosion of interfaces, ununderstandable and not needed abstraction layers and general confusion - that's what we got as a result. BUT, we also get very very nice skeleton to build on top of. Especially - when it comes to Repository that we actually used. We have 2 entirely diffrent databases (firestore and mongo) and one in-house implemented (by a humble author of this post) in-memory DB mocking the firestore behaviour. So we really can simply mock any behaviour we want, and the most common dependency to the DB is simply non-existent. We simply change the implementation to "mock-db" and define whatever we need for the test. Exchange to MongoDB was also very simple in comparation to what it could have been without having extracted right interfaces... But... One have to admit - it has taken a LOT of work to bring the code to this level. Probably any of those issues might have been solved in less time simply by brute-forcing code edition. :>
@alexhyettdev
@alexhyettdev 8 ай бұрын
Yes swapping out a DB for a mock DB is a good use case.
@marna_li
@marna_li 7 ай бұрын
I wouldn't say that "interface" in interface segregation is about C# or Java interfaces. Simply that you should segregate the interface for your class. It could be an interface, but not necessarily. So I try to keep it a language neutral term. Keep up the good work! I find it great.🙂
@alexhyettdev
@alexhyettdev 7 ай бұрын
Yes indeed, I believe the original paper was for C++ and the interfaces he was referring to were abstract classes.
@jneves8827
@jneves8827 8 ай бұрын
Thanks so much, I don't understand english very well. However, I really figured out your explanation and gained more one follower.
@alexhyettdev
@alexhyettdev 8 ай бұрын
That's awesome, I am glad I helped.
@Ne1gh_
@Ne1gh_ 2 ай бұрын
Thanks!
@KaznarahAndrinarivo
@KaznarahAndrinarivo 6 сағат бұрын
Thanks 🙏
@residentcitron
@residentcitron 8 ай бұрын
In the context of the Interface Segregation Principle (ISP), when we refer to a "client," we're talking about a class, module, or component that uses or depends on an interface, not a class that implements the interface. ISP states that clients should not be forced to depend on methods they do not use (call / invoke). If a class has three methods but the client only calls one of them, the client still has a compile-time dependency (due to the import statement) on the other two methods. The methods could be: retrieve(), save() and delete(). If the client code only calls save(), then it is cleaner for the client code to depend on a 'Saver' interface, rather than the concrete class which implements all three methods. Also, it is easier to use simple interface both on the caller's (client) side and on the implementation side.
@alexhyettdev
@alexhyettdev 8 ай бұрын
Yes, that is a good point. There appear to be 2 ways to interpret ISP with the internet being split on which one to use. You are right, the original paper does state it is to make life simpler for clients by only including methods used by that client in the interface. Of course, this does depend on who the client is and whether it is part of your codebase. If the client is unknown the only way to satisfy this version of ISP is to have one method per interface which is obviously an anti-pattern. Either way, keeping interfaces as small as possible and avoiding fat interfaces is always good practice. I managed to find the original paper if anyone is interested in reading it: web.archive.org/web/20150905081110/www.objectmentor.com/resources/articles/isp.pdf It seems to be a common misconception. Even some articles on the Microsoft website get it wrong: learn.microsoft.com/en-us/archive/msdn-magazine/2014/may/csharp-best-practices-dangers-of-violating-solid-principles-in-csharp#the-interface-segregation-principle
@osivwiokiti9897
@osivwiokiti9897 10 ай бұрын
Best explanation of solid I've seen. thanks.
@alexhyettdev
@alexhyettdev 10 ай бұрын
Thank you! I am glad it was helpful. Thanks for leaving a comment 👍
@217-sritejrajulu6
@217-sritejrajulu6 8 ай бұрын
this guy is so awesome he explaiend stack and heap in suck a way ill remember forever
@alexhyettdev
@alexhyettdev 8 ай бұрын
Thank you! I am glad I could help.
@terry-
@terry- 2 ай бұрын
Great!
@sebon11
@sebon11 10 ай бұрын
Btw man - do you mind explaining CI & CD in one of your future videos? Would love that!
@alexhyettdev
@alexhyettdev 10 ай бұрын
Yes no problem will add it to the backlog!
@sebon11
@sebon11 10 ай бұрын
@@alexhyettdev great!
@alexhyettdev
@alexhyettdev 9 ай бұрын
Here you go 😉 kzbin.info/www/bejne/pmS6Y4t5eZimo80
@sebon11
@sebon11 9 ай бұрын
@@alexhyettdev damn that's super lovely! Thank you for getting back here, dude!
@vishalkarthik.v7209
@vishalkarthik.v7209 8 ай бұрын
For decorative pattern , instead of using it can't we just copy code and modify , in what scenario does it help 🙂, I couldn't get clarity in this part
@alexhyettdev
@alexhyettdev 8 ай бұрын
Yes you could do that but it would be breaking the Don’t Repeat Yourself principle. If the code needs to be vastly different then copying is fine. It’s to avoid the case of updating one part but forgetting the other part that got copied. It is mainly for when you need to add a small piece of functionality (before or after original implementation) that doesn’t apply to every use case. Therefore you avoid breaking existing callers of the method but make use of not duplicating the code.
@ehm-wg8pd
@ehm-wg8pd 2 ай бұрын
4:58 addressing the issue i have right now
@naufalikhlasksatria9228
@naufalikhlasksatria9228 6 ай бұрын
Indonesian spokeswoman said : Soliiiid?
@yazanmansour1231
@yazanmansour1231 9 ай бұрын
you are amazing best video for SOLID
@alexhyettdev
@alexhyettdev 9 ай бұрын
Thank you Yazan! I am glad you liked it 👍👍
@MagoMakes
@MagoMakes 7 ай бұрын
Just some friendly feedback. Really well written and narrated. BUT your code presentations were far too quick/short giving hardly any time to digest. Users generally hate pausing and rewinding. Maybe less shots of you and your face, leaving the code up longer. From an adult education perspective this would be a lot better. Not everyone has the same processing speed. Also, if you kept it this short because of algorithms etc, be mindful of whose needs you are really trying to meet: your consumers, yours or KZbin's....
@alexhyettdev
@alexhyettdev 7 ай бұрын
Thanks for the feedback, I will try and keep the code up for longer. I don’t intentionally try and keep the videos short. It is just how long they tend to come out when I am recording them.
@thathue
@thathue 4 ай бұрын
for me rewinding or pausing is part of learning from videos, also shorter vidoes help alot to motivate me to consume them
@mymacaintwag
@mymacaintwag 6 ай бұрын
Here are the principles and here is a class. I have no classes!
@alexhyettdev
@alexhyettdev 6 ай бұрын
Yes the SOLID principles are mostly for OOP languages such as C# and Java. Some of them are still useful for other languages though.
@xyyx1001
@xyyx1001 8 ай бұрын
Easiest SOLID explanation, especially SRP. Too many others parrot abstract concepts without a concrete example.
@alexhyettdev
@alexhyettdev 8 ай бұрын
Thank you! I am glad you liked it. Yes I don’t think they really understand them when they do that.
@lysithea9293
@lysithea9293 9 ай бұрын
As a beginner programmer, I found your video much clearer than the others I've watched on the SOLID principles. One thing I'm still unsure about, should child classes implement all arguments defined in the constructor of the parent class? (I guess that would belong to the Interface Segregation part) E.g. (don't mind the made up syntax) ParentClass: constructor(a, b, c = true, d = false): self.a = a self.b = b self.c = c self.d = d ChildClassA extends ParentClass: # doesn't define a new constructor and uses # all the arguments of the parent's constructor ChildClassB extends ParentClass: constructor(a, b, e): super.constructor(a, b) self.e = e Does the fact that arguments 'c' and 'd' are unused in ChildClassB break the SOLID principles?
@alexhyettdev
@alexhyettdev 9 ай бұрын
I don’t see a problem with this. The SOLID principles only really occur once an object has been created. As long as your child class can still do everything that the parent can it won’t break the LSP. I think the only time I would be worried about constructor arguments is if the order is implied somehow and missing one out will cause confusion. e.g. ParentPosition(x, y, z, t) ChildPosition(x, z, t) Without looking at the constructor definition you would assume the child would be (x, y, z)
@lysithea9293
@lysithea9293 9 ай бұрын
@@alexhyettdev Great! Thanks a lot for your reply and good point on the arguments' order.
@nooruddinraotiwala353
@nooruddinraotiwala353 2 ай бұрын
last minutes hillarious😅
@mj65535
@mj65535 3 ай бұрын
I always find single responsibility principle problematic when it comes to OO design. People end up moving away from "it is" classes to "it does" classes. This reduces "it can be reused".
@testingfsqc
@testingfsqc 5 ай бұрын
This is a SOLID video on S.O.L.I.D!
@alexhyettdev
@alexhyettdev 5 ай бұрын
Thank you!
@jamestacular
@jamestacular 6 ай бұрын
The open closed principal is the only one that I don't think is realistic. Basically the way I understand it is once your write code it becomes untouchable. You can only add to it but coding around the original implementation by using extension methods or new implementations of the original interface.
@alexhyettdev
@alexhyettdev 6 ай бұрын
I think it makes sense if your code is being published as part of library for others to use. You wouldn't want to introduce bugs into trusted code. If you are working on a closed source application in a small team then I can see it being unrealistic. I guess the better approach is to think, "how can I design this, so I won't need to change the interface in the future?"
@technicaltheb034
@technicaltheb034 11 ай бұрын
It'd be great if you write code while explaining.
@alexhyettdev
@alexhyettdev 11 ай бұрын
Thanks for the feedback. Yes I can definite do that more often.
@sebon11
@sebon11 11 ай бұрын
I don't have that feeling, for me everything was understandable here
@SeriousCat5000
@SeriousCat5000 8 ай бұрын
@3:51 Mom class is hot AF
@alexhyettdev
@alexhyettdev 8 ай бұрын
😂
@eio4528
@eio4528 5 ай бұрын
I don't want to argue against SOLID principles because I can't say I completely and fully follow every rule. However, extending classes to avoid changing them sounds like a long term recipe for disaster. A codebase I once worked had a main class for a product with a ridiculous amount of additional classes that extended it for all kinds of functionality that was introduced over time. It quickly became a huge mess. I argue that there are absolutely moments where a class can and should be changed. It seems to me many of these principles are designed to help prevent a developer from stepping on their own toes. I argue people should pay closer attention to what they're doing and if they don't understand the code they're changing, they're doomed to make mistakes. They need to understand the code! It's like a mechanic modifying a car without knowing how the engine truly works, IMO. You're doomed if that is the case.
@anlcangulkaya6244
@anlcangulkaya6244 8 ай бұрын
How to be worst programmer principles
@alexhyettdev
@alexhyettdev 8 ай бұрын
Some of them have merit but if you follow them religiously you can end up writing words code definitely.
@anlcangulkaya6244
@anlcangulkaya6244 8 ай бұрын
@@alexhyettdev I'm following get the job done principle using C or C++ unsafe and fast code using SIMD and data oriented design
@alanjohnson7374
@alanjohnson7374 2 ай бұрын
Why wouldn't you make parent inherit from child in your example... problem solved.
@DoctorMoax
@DoctorMoax 4 күн бұрын
not exactly a beginner friendly content. Other's have done a better explanation
@PopLucian90
@PopLucian90 6 ай бұрын
Going a bit too fast. But good info otherwise.
@alexhyettdev
@alexhyettdev 6 ай бұрын
Thanks, yeah still trying to find the right balance. I have a tendency to talk to faster when in front of a camera 🤦🏻‍♂️.
@charlitowashere5906
@charlitowashere5906 2 ай бұрын
your git commit... //my code is more important than yours... jajajaja
Bitwise Operators and WHY we use them
8:41
Alex Hyett
Рет қаралды 56 М.
5 Design Patterns That Are ACTUALLY Used By Developers
9:27
Alex Hyett
Рет қаралды 151 М.
Маленькая и средняя фанта
00:56
Multi DO Smile Russian
Рет қаралды 2,4 МЛН
The magical amulet of the cross! #clown #小丑 #shorts
00:54
好人小丑
Рет қаралды 19 МЛН
Зомби Апокалипсис  часть 1 🤯#shorts
00:29
INNA SERG
Рет қаралды 6 МЛН
Domain Driven Design: What You Need To Know
8:42
Alex Hyett
Рет қаралды 86 М.
Learn SOLID Principles with CLEAN CODE Examples
28:35
Amigoscode
Рет қаралды 255 М.
How to write SOLID C++
29:22
platis.solutions
Рет қаралды 36 М.
Solid Programming - No Thanks
32:00
ThePrimeTime
Рет қаралды 201 М.
How Senior Programmers ACTUALLY Write Code
13:37
Healthy Software Developer
Рет қаралды 1,3 МЛН
Event-Driven Architecture: Explained in 7 Minutes!
7:18
Alex Hyett
Рет қаралды 72 М.
The purest coding style, where bugs are near impossible
10:25
Coderized
Рет қаралды 828 М.
5 Types of Testing Software Every Developer Needs to Know!
6:24
Такого вы точно не видели #SonyEricsson #MPF10 #K700
0:19
BenJi Mobile Channel
Рет қаралды 3,4 МЛН
APPLE УБИЛА ЕГО - iMac 27 5K
19:34
ЗЕ МАККЕРС
Рет қаралды 87 М.
What % of charge do you have on phone?🔋
0:11
Diana Belitskay
Рет қаралды 288 М.
Apple ХОЧЕТ, чтобы iPhone ЛОМАЛИСЬ чаще?
0:47
ÉЖИ АКСЁНОВ
Рет қаралды 762 М.
Пленка или защитное стекло: что лучше?
0:52
Слава 100пудово!
Рет қаралды 1,5 МЛН