Christopher Okhravi
Christopher Okhravi
  • 209
  • 7 393 546
Liskov Substitution Principle (SOLID)
Violating the 7 rules of the Liskov Substitution Principle (L in SOLID) leads to code that is difficult to reason about. The 3 type rules can be checked by compilers but the 4 behavioral rules have to be respected by us developers.
⭐️ More about LSP in Clean Architecture (Chapter 9): geni.us/IBhtLnh
Watch First: ua-cam.com/video/FdFBYUQCuHQ/v-deo.html
📄 The paper: dl.acm.org/doi/pdf/10.1145/197320.197383
🏛️ Design By Contract: en.wikipedia.org/wiki/Design_by_contract
CONTENTS
00:00 Intro
01:33 Formal Definition
02:56 Robustness Principle
06:09 Type Rules
08:50 Terminology
11:59 Behavioral rules
19:15 Conclusion
Переглядів: 6 197

Відео

8 Wastes of Lean (for Software Developers)
Переглядів 8 тис.День тому
Applying the 8 Wastes (mudas) of Lean Manufacturing to Software Development helps us understand how to produce more value ✨, with less waste 🗑️. Check out the books below: 🚀 geni.us/iP1SF (Lean Startup) 🚘 geni.us/mgAIH8G (Toyota Way) 🎯 geni.us/BXDX (The Goal) CONTENTS 00:00 Intro 00:16 What is Lean? 01:15 Overproduction 02:17 Overprocessing 03:33 Defects 04:36 Inventory 06:52 Transportation 07:...
Only Use Inheritance If You Want Both of These
Переглядів 11 тис.14 днів тому
Inheritance gives us hierarchical reuse of code AND subtype polymorphism. In this video I argue that we should only ever use it if we want BOTH. patreon.com/christopherokhravi 📚 Recommended Reading: geni.us/nlbA6 (Head First: Design Patterns) geni.us/PsXmo (Design Patterns: Elements of Reusable Object-Oriented Software) Watch next: ua-cam.com/video/YaSMkzmc_sA/v-deo.html ua-cam.com/video/TkUhAb...
7 Tips to Grow as a Developer
Переглядів 14 тис.21 день тому
I meet many programming students. Here are 7 opportunities to grow that I see time and time again. 🙌 patreon.com/christopherokhravi Books and talks from mentors that have shaped the way I think: SANDI METZ ⚙️ geni.us/APcJLnI (Practical Object-Oriented Design) ua-cam.com/video/OMPfEXIlTVE/v-deo.html (Nothing is Something) MARTIN KLEPPMANN 🏛️ geni.us/Pj6IS4U (Designing Data-Intensive Applications...
Depend on Abstractions not Concretions (Framework)
Переглядів 14 тис.Місяць тому
I made this simple framework to explain why and how we should "depend on abstractions and not on concretions". It's a quadrant diagram where the two dimensions captures the principles "program to interfaces, not implementations" and "dependency injection". 🏛️ geni.us/IBhtLnh (Clean Architecture) 🧠 geni.us/CpLx2y (Agile Principles, Patterns, and Practices) 🌟 geni.us/zzlx (Dependency Injection: P...
3 Reasons WHY Waterfall Doesn't Work
Переглядів 4,5 тис.Місяць тому
Three simple models that explain why and when the Waterfall method cannot work. 🎓 References: - geni.us/1obVBO [Rubin, K. S. (2012). Essential Scrum: A practical guide to the most popular Agile process. Addison-Wesley., Fig. 3.7] - users.ece.utexas.edu/~perry/education/SE-Intro/lehman.pdf [Lehman, M. M. (1980). Programs, life cycles, and laws of software evolution. Proceedings of the IEEE, 68(9...
They Knew Waterfall Didn't Work
Переглядів 12 тис.Місяць тому
Did you know that the paper that introduced the Waterfall method said that it is "risky and invites failure". They knew it didn't work. ⚠️ Watch next: ua-cam.com/video/yhwaisT0VTM/v-deo.html 🌟 Join the Patreon www.patreon.com/christopherokhravi 📚 Recommended Reading: geni.us/1obVBO (Essential Scrum) 📜 Royce, Winston. (1970). Managing the development of large software systems. blog.jbrains.ca/as...
Always Use Interfaces
Переглядів 43 тис.Місяць тому
How to follow the principle of Couple To Abstractions, Not Concretions, and how to avoid tempting others to break the rule. 🎓 Get the book: geni.us/hNDE Watch before: ua-cam.com/video/YaSMkzmc_sA/v-deo.html Watch next: ua-cam.com/video/SeN1s65tRHY/v-deo.html FURTHER RECOMMENDED READING: - geni.us/zzlx (Dependency Injection: Principles, Practices, and Patterns) - geni.us/IBhtLnh (Clean Architect...
Understanding Covariance and Contravariance
Переглядів 10 тис.Місяць тому
The intuition behind Covariance and Contravariance explained with 🍎, oranges 🍊, and cats 🐈. 00:00 Question 00:41 Fruit example (Covariance) 01:14 Fruit example (Contravariance) 02:03 UML (Covariance) 03:24 UML (Contravariance) 04:53 Formal definitions 06:12 Type safety 07:16 Robustness Principle 08:20 Invariant list (Covariance) 09:43 Invariant list (Contravariance) 10:59 Invariant list (summar...
3 Ideas on Refactoring by Martin Fowler
Переглядів 19 тис.Місяць тому
Nuggets from one of the most iconic programming books of all time. 🔥 Get the book! geni.us/k8KhT3 ▶️ Watch this next: ua-cam.com/video/v9ejT8FO-7I/v-deo.htmlsi=G4rUIATVohCU_lwM 00:00 Intro 00:09 Idea 1 01:27 Idea 2 03:27 Book 03:46 Idea 3 05:40 Outro
The Square-Rectangle Problem
Переглядів 9 тис.2 місяці тому
The Square-Rectangle Problem
The Only Time You Should Use Polymorphism
Переглядів 85 тис.2 місяці тому
The Only Time You Should Use Polymorphism
Object Oriented Programming - Lecture 2 - Paradigms, Types, Compilation, Purity, Programs
Переглядів 41 тис.3 роки тому
Object Oriented Programming - Lecture 2 - Paradigms, Types, Compilation, Purity, Programs
Object Oriented Programming - Lecture 1 - Overview of contents
Переглядів 27 тис.3 роки тому
Object Oriented Programming - Lecture 1 - Overview of contents
My Vim Setup #2 (Mappings / Custom shortcuts)
Переглядів 38 тис.5 років тому
My Vim Setup #2 (Mappings / Custom shortcuts)
My Vim Setup #1 (Job Control)
Переглядів 41 тис.5 років тому
My Vim Setup #1 (Job Control)
Reactive Programming from Scratch (JavaScript) - Ep3
Переглядів 6 тис.5 років тому
Reactive Programming from Scratch (JavaScript) - Ep3
Reactive Programming from Scratch (JavaScript) - Ep2
Переглядів 6 тис.5 років тому
Reactive Programming from Scratch (JavaScript) - Ep2
Reactive Programming from Scratch (JavaScript) - Ep1
Переглядів 29 тис.5 років тому
Reactive Programming from Scratch (JavaScript) - Ep1
(Ep2) Mandala Maker in JavaScript (functional style)
Переглядів 2,2 тис.5 років тому
(Ep2) Mandala Maker in JavaScript (functional style)
(Ep1) Mandala Maker in JavaScript (functional style)
Переглядів 3,7 тис.5 років тому
(Ep1) Mandala Maker in JavaScript (functional style)
Ramda JS Tutorial - Part 40 (filter)
Переглядів 2,4 тис.5 років тому
Ramda JS Tutorial - Part 40 (filter)
Todo App in Vue.js - The Hard Way (Ep18)
Переглядів 3,1 тис.5 років тому
Todo App in Vue.js - The Hard Way (Ep18)
Todo App in Vue.js - The Hard Way (Ep17)
Переглядів 1,8 тис.5 років тому
Todo App in Vue.js - The Hard Way (Ep17)
Vue.js - The Hard Way (Ep16)
Переглядів 1,5 тис.5 років тому
Vue.js - The Hard Way (Ep16)
Vue.js - The Hard Way (Ep15)
Переглядів 1,7 тис.5 років тому
Vue.js - The Hard Way (Ep15)
Vue.js - The Hard Way (Ep14)
Переглядів 1 тис.5 років тому
Vue.js - The Hard Way (Ep14)
Vue.js - The Hard Way (Ep13)
Переглядів 1,2 тис.5 років тому
Vue.js - The Hard Way (Ep13)
Ramda JS Tutorial - Part 39 (T, F)
Переглядів 1 тис.5 років тому
Ramda JS Tutorial - Part 39 (T, F)
Vue.js - The Hard Way (Ep12)
Переглядів 1,4 тис.5 років тому
Vue.js - The Hard Way (Ep12)

КОМЕНТАРІ

  • @user-ev9jg6ts6e
    @user-ev9jg6ts6e 3 години тому

    Excellent as always. How soon will you publish your own book?)

  • @lavanyam3224
    @lavanyam3224 6 годин тому

    Your explanation is lit ❤ I read the book explanation after your video and it made so much sense! You made it so easy ;)

  • @FritsvanDoorn
    @FritsvanDoorn 18 годин тому

    You make this difficult subject easy to understand. Thank you.

  • @jussiheino
    @jussiheino 19 годин тому

    Here's my invariant: sometimes I'd like to give a bigger thumbs-up than others. This is a good lesson! Worth re-uploading the corrected version, good stuff, can recommend.

  • @nullset11
    @nullset11 День тому

    How many attempts at the orange juggle before camera perfect? 😄

  • @harshkuddu4386
    @harshkuddu4386 День тому

    Bro I been saying this for years, no way.

  • @kumarchandan6336
    @kumarchandan6336 День тому

    I have cracked Low Level Design interviews in companies like Microsoft, Amazon, Atlassian, Flipkart, etc with the help of your videos. Your videos are really helpful. Keep up the good work.

  • @KhakiShow
    @KhakiShow 2 дні тому

    2024, saving lives.

  • @ajzack983
    @ajzack983 2 дні тому

    Liberal is weaker, conservative is stronger. Got it.

  • @devid6799
    @devid6799 2 дні тому

    Greetings from Germany. I love you!

  • @albertwang5974
    @albertwang5974 3 дні тому

    Be a nice guy, and don't expect every one will be a nice guy!

  • @albertwang5974
    @albertwang5974 3 дні тому

    Don't be a trouble maker, and don't fail if you have to work with a trouble maker!

  • @arastusharma439
    @arastusharma439 3 дні тому

    Pure Majic in Explanation !! Didn't realise the time while watching it and it seems like just now started.Thankyou for such good content!

  • @alejandroioio6784
    @alejandroioio6784 3 дні тому

    😎

  • @Silverflame1
    @Silverflame1 3 дні тому

    You can also find a lot of information about the problem of subtyping if you look up "Circle-ellipse problem".

  • @miguelcerne1150
    @miguelcerne1150 3 дні тому

    The first Design Patterns Series that really simplifies and doesn't overcomplicates the basics! You're the best, keep up with the channel please!

  • @Wojmasz
    @Wojmasz 3 дні тому

    great piece of knowledge! thank you!

  • @johncerpa3782
    @johncerpa3782 3 дні тому

    Great video, thank u

  • @patrickstephen7885
    @patrickstephen7885 4 дні тому

    Your content is amazing. Great stuff

  • @waleedelwakeel5721
    @waleedelwakeel5721 4 дні тому

    That's amazing. I am always eager to understand pure concepts rather technology coupled ones. I appreciate your interest in that matter and you are truly killing it. Thank you for your efforts and I hope you continue sharing your great knowledge.

  • @javiermorin3110
    @javiermorin3110 4 дні тому

    I love all your videos! Thank you so much for taking the time to make them!

  • @tibrec8
    @tibrec8 4 дні тому

    nice as always bro , can make technical practice video for this .

  • @bogdanf6698
    @bogdanf6698 4 дні тому

    comment for support! thanks! I'll get back here in 2 years :D after I have learned enough to understand the explication

  • @MarkMifsud
    @MarkMifsud 4 дні тому

    Your explanations are long winded, but they are clear and that's why they are really helpful. Thanks.

    • @ChristopherOkhravi
      @ChristopherOkhravi 4 дні тому

      Please do let me know if you start to think that I'm becoming way too repetitive 😊 Thank you for watching and for the feedback 😊🙏

    • @michaelhaddad2190
      @michaelhaddad2190 3 дні тому

      @@ChristopherOkhravi Absolutly not. Every second of every video is gold.

  • @wilkesreid
    @wilkesreid 4 дні тому

    This seems kind of obvious to me. If B is a subclass of A and “x” is an instance of some subclass of A, and you could have x.fido() calls anywhere, then it would be utter chaos because x could be an instance of B in any of those places and B could have overridden fido to behave so differently that your code can’t know what to expect as a result of x.fido() because it could be anything. If I expect x.fido() to return an array, then an array of objects, or array of ints is fine, but of course you shouldn’t override it to return an object or some struct. And if the arguments given to x.fido() could be any integer, then of course you shouldn’t reject whatever would normally be acceptable to A for that method.

  • @demarcorr
    @demarcorr 4 дні тому

    covariance and contravariance are probably one of those things i understand subconsciously but can never seem wrap my head around consciously

  • @amerbashoeb2106
    @amerbashoeb2106 4 дні тому

    Thank you!

  • @detaaditya6237
    @detaaditya6237 4 дні тому

    Wow I never thought Postel's Law is related with LSP. It makes a lot of sense, though!

  • @ReviewSutras
    @ReviewSutras 4 дні тому

    Can we have examples?

  • @felipecardoso3142
    @felipecardoso3142 4 дні тому

    Great explanation indeed, but the remaining question is: When will you instantiate the objects? This has to happen somewhere, right? One cannot have infinite levels of abstraction...

  • @nullcheque
    @nullcheque 4 дні тому

    Before I even finish this video-big thank you for the Elegant Objects recommendation in your other video about Always Using Interfaces. I am about halfway through the book, and in conjunction with your content about coupling to abstractions, my understanding and use of OOP has already begun greatly improving the code I write at work.

  • @wjrasmussen666
    @wjrasmussen666 4 дні тому

    Bag of fruit has apples, bananas, grapes, oranges.....

  • @greob
    @greob 4 дні тому

    Very nice presentation, easy to follow and understand. Thanks for sharing!

  • @mortenbork6249
    @mortenbork6249 4 дні тому

    If you use composition over inheritance, and DI with interfaces, and not types. You can't violate LSP, because the rules are inherently followed. This is actually one of the reasons that composition is better than inheritance.

    • @Robert-yw5ms
      @Robert-yw5ms 4 дні тому

      This is wrong. Every interface exposes a contract. When you implement that interface, you have to fulfill that contract. Otherwise you're breaking the lsp. Example you have an interface IStack with the normal stack methods and you then implement it in a FIFO way. You've just broken lsp.

    • @TuxCommander
      @TuxCommander 4 дні тому

      Wrong. You literally ignoring the fundamental aspect of LSP. As stated in the video, it's mainly about behaviour not design which would be detected by the compiler.

    • @mortenbork6249
      @mortenbork6249 4 дні тому

      ​@@Robert-yw5ms And your compiler will prevent you from not fulfilling the contract. You can't break it.

    • @Robert-yw5ms
      @Robert-yw5ms 4 дні тому

      @@mortenbork6249 It won't prevent you from breaking the behavioural contract. Read the example I gave and try to understand it.

    • @Robert-yw5ms
      @Robert-yw5ms 4 дні тому

      @@mortenbork6249 Type definitions are only one part of the contract. Behaviour is the other. Read the example I gave and try to understand it. Or watc the video from 12 minutes. Each interface promises to have certain preconditions, post conditions and invariants.

  • @grossd18
    @grossd18 4 дні тому

    Can it be worthwhile to apply these principles to interface evolution, when a need for backwards compatibility is desireable. It seems that yes, it could apply.

  • @peteralexandre6593
    @peteralexandre6593 4 дні тому

    Thanks for this amazing content. It might be dumb to ask but being a non native english speaker what is this word you are using in a lot of your videos wich sounds like "hirokee" ? Need to know how to spell it to search for the definition 😅

    • @ChristopherOkhravi
      @ChristopherOkhravi 4 дні тому

      I think you are referring to “hierarchy”, no? Do note that all my new videos have accurate closed captions. So be sure to turn those on if you find the way I speak confusing. Which is understandable since I’m not a native English speaker either 😊😊😊 Thank you for watching and for asking. 😊🙏

    • @peteralexandre6593
      @peteralexandre6593 4 дні тому

      Yeah that's hierarchy thank you so much. No no your English accent is perfect I understand 99% of your videos even without captions it's just that I was not used to the word hierarchy in English. See, you make me a better developer and make me improve my English at the same time. Thanks again.😊

  • @PixelSergey
    @PixelSergey 4 дні тому

    Interesting! How would one implement classes such as UniqueList or ImmutableList while still following these principles? It seems so natural to just write a bunch of code for a base List class, and then just make a subclass that inherits this code but adds extra checks (for immutability or uniqueness). How do we do this in other ways?

    • @Robert-yw5ms
      @Robert-yw5ms 3 дні тому

      Simple: don't inherit from list. But there's nothing stopping you using a list as a backing field

  • @silberwolfSR71
    @silberwolfSR71 4 дні тому

    Amazing video as usual! I think an interesting thing to point out is that many of these different "software design principles" complement each other, each making use of the others easier and more effective. For instance, preferring to code to interfaces makes adhering to the Liskov Substitution Principle much easier, because there are usually no invariants relating to state. Similarly, interface segregation leads to small interfaces, whose invariants are easier to grasp and enforce. Sharing code through composition rather than inheritance bypasses substitution concerns entirely, since there's no subtyping involved.

    • @ChristopherOkhravi
      @ChristopherOkhravi 4 дні тому

      Indeed. I very much agree. Thanks for pointing this out 😊🙏 And thanks for watching 😊

  • @filippobuonco95
    @filippobuonco95 4 дні тому

    Lovely! Thanks for this video! I have a question, is a violation of the LP if a method in the subclass accept more parameters (meaning not a bigger range of values of the parameter, but really the number of parameters the method is getting as input) than the method in the superclass?

    • @ChristopherOkhravi
      @ChristopherOkhravi 4 дні тому

      Thank you for the detailed question. In my reading I would say that more parameters is not a violation as long as it still can be called just like you can call the super class. So the additional parameters would have to be optional for this to work. Otherwise this is actually not being liberal but rather being conservative. Off the top of my head I cannot however think of languages that would support this. Did you have some language or example in mind? Thank you again 😊🙏

    • @Robert-yw5ms
      @Robert-yw5ms 4 дні тому

      @@ChristopherOkhravi Javascript supports this without issue. class Parent { foo(x) { console.log(x) } } class Child extends Parent { foo(x,y) { console.log(x,y) } } new Child().foo(1,2); Although in a sense the parent foo method will also accept any number of arguments. It'll just ignore the extra ones. It will also accept fewer parameters and treat x as undefined. I'd also say that adding overloads with different parameter counts in c# or java is another example. Which clearly doesn't break LSP.

    • @ChristopherOkhravi
      @ChristopherOkhravi 4 дні тому

      @@Robert-yw5ms Silly of me to not immediately think of JavaScript 😊😊Thank you for the reply. Overloading however does not need to respect LSP. LSP applies when we are overriding, or more generally: when we have dynamic dispatch as a consequence of subtype polymorphism. So in other words, interface implementation (in languages like C# and Java) also needs to respect LSP.

    • @Robert-yw5ms
      @Robert-yw5ms 4 дні тому

      ​@@ChristopherOkhravi Although it is worth noting that this is one of many issues with javascript that typescript fixes. I hope people don't read my comment and think "oh amazing let's do that" :D And I agree completely with your second paragraph.

  • @pixaz
    @pixaz 4 дні тому

    14:33 the same argument could be made when you say same or weaker precondition. If we have a base type of UniqueListBase with a precondition, on the Add method that you cannot add duplicates, and subtype of UniqueListDerived that isnt restricting the uniqueness. That would also be a violation of liskov no? if somewhere down the road, people are using UniqueListDerived as a UniqueList, it might cause them problem

    • @ChristopherOkhravi
      @ChristopherOkhravi 4 дні тому

      I think I understand what you mean but tell me if it seems like I don’t. According to LSP, the example you give would not be a violation. It is ok to make preconditions weaker. So if the subtype wants to get rid of the requirement that we cannot add items that are already in the list that would be perfectly fine. If you however have a postcondition or an invariant that says that items may not be duplicated in the list then that cannot be weakened in the subtype. And if your base type is called UniqueList then it would (imho) make sense for us to think of it as having postconditions or invariants enforcing uniqueness of elements. Makes sense? Thanks for the detailed comment and for watching 😊🙏

    • @pixaz
      @pixaz 4 дні тому

      @@ChristopherOkhravi oh i seeee! thanks for the response!

  • @RobertShresthawolf
    @RobertShresthawolf 4 дні тому

    First one here :)

  • @Luuncho
    @Luuncho 5 днів тому

    I love lean

  • @bunglegrind1
    @bunglegrind1 5 днів тому

    An enlightening reading is smalltak objects and design by chaimond liu, chapter 17. The problem with class inheritance is that it allows method overrides, which in practice violate LSP. If the instances are read-only you don't override get/set and LSP is satisfied

  • @kirilmicev843
    @kirilmicev843 5 днів тому

    I think this MUDA concept will have very big acceptance in Serbia.

  • @alejandroioio6784
    @alejandroioio6784 5 днів тому

    😎

  • @alejandroioio6784
    @alejandroioio6784 5 днів тому

    😎

  • @Greenmarty
    @Greenmarty 5 днів тому

    i have never read the original paper but to my humble understanding, Waterfall makes sense in projects where requirements are basically "given" from the beginning and can't be changed without deep analysis e.g. in military applications etc.

    • @ChristopherOkhravi
      @ChristopherOkhravi 3 дні тому

      Completely agree. You might be interested in this other video on when Waterfall works: ua-cam.com/video/yhwaisT0VTM/v-deo.html

  • @arastusharma439
    @arastusharma439 5 днів тому

    Such a MasterPiece it is !!!! Awesome Explanation

  • @glenndify1
    @glenndify1 6 днів тому

    Awesome explanation

  • @elhaambasheerch7058
    @elhaambasheerch7058 6 днів тому

    One of my favourite resources to learn OOP.