Unveil the Mystery of the Liskov Substitution Principle

Поділитися
Вставка
  • Опубліковано 12 бер 2024
  • Become a sponsor to access source code ► / zoranhorvat
    Join Discord server with topics on C# ► codinghelmet.com/go/discord
    Enroll course Beginning Object-Oriented Programming with C# ► codinghelmet.com/go/beginning...
    Subscribe ► / @zoran-horvat
    Have you ever exclaimed that this or that method violates LSP, looking so bright in the team but, deep inside, hoping nobody would ask you to explain?
    Have you ever raised your voice when someone mentioned LSP but, deep inside, you knew it was because you lacked the words to say it better?
    Spare a few minutes to learn what makes LSP so hard, but also to learn how to sort it out in your head once and for all.
    ▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬
    👨 About Me 👨
    Hi, I’m Zoran, I have more than 20 years of experience as a software developer, architect, team lead, and more. I have been programming in C# since its inception in the early 2000s. Since 2017 I have started publishing professional video courses at Pluralsight and Udemy and by this point, there are over 100 hours of the highest-quality videos you can watch on those platforms. On my UA-cam channel, you can find shorter video forms focused on clarifying practical issues in coding, design, and architecture of .NET applications.❤️
    ▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬
    ⚡️RIGHT NOTICE:
    The Copyright Laws of the United States recognize a “fair use” of copyrighted content. Section 107 of the U.S. Copyright Act states: “Notwithstanding the provisions of sections 106 and 106A, the fair use of a copyrighted work, including such use by reproduction in copies or phono records or by any other means specified by that section, for purposes such as criticism, comment, news reporting, teaching (including multiple copies for classroom use), scholarship, or research, is not an infringement of copyright." This video and our youtube channel, in general, may contain certain copyrighted works that were not specifically authorized to be used by the copyright holder(s), but which we believe in good faith are protected by federal law and the Fair use doctrine for one or more of the reasons noted above.
    #csharp #dotnet #objectorientedprogramming
  • Наука та технологія

КОМЕНТАРІ • 40

  • @aleksandrm3466
    @aleksandrm3466 2 місяці тому +8

    I love that channel, thanks for the contribution

  •  2 місяці тому +2

    Thinking Why: it's a threshold for mid level programmer. Too often I see programmers who do "by example" without any reasoning Why.

  • @kaihusravnajmiddinov5413
    @kaihusravnajmiddinov5413 Місяць тому +1

    The slow mode of your speech and clear pronunciation, which are present, are the advantage of your content.
    Teaching methods matter.

  • @luc9volts
    @luc9volts 2 місяці тому +5

    Yeah ! Science!

  • @adambickford8720
    @adambickford8720 2 місяці тому +3

    LSP is probably more obvious/intuitive than you think; it just means more lenient inputs and more restrictive outputs are legal. Imagine something like `Object doStuff(ICollection input)` (i'm a java dev, don't get hung up on api specifics!).
    If you subclass this, it's completely fine to return, well, anything because it's almost impossible to break the contract of `Object` (its also not very useful!). Any callers expecting `Object` as a return from the super class will be just fine w/you returning, say, a string.
    However, you can't make the subclass take something like an `IList` because the caller wasn't expecting that from the parent. Note that if the parent had required an `IList` its perfectly fine for you to loosen the contract and take an `ICollection` (this is usually fairly intuitive)
    It can be a bit trickier w/o explicit types. Imagine a function that returns an int, but semantically its always positive. You could subclass that and now return negative values as well, but that breaks the contract. w/o some kind of `PositiveInteger` type, you can't express this constraint as easily.

    • @zoran-horvat
      @zoran-horvat  2 місяці тому +5

      Yes that is pretty much what I said in the video.

    • @adambickford8720
      @adambickford8720 2 місяці тому

      @@zoran-horvat I find concrete examples drive things home. ymmv.

    • @muhammadumair9074
      @muhammadumair9074 2 місяці тому

      @@zoran-horvatYeah but this time Adam explains it with the code :) It is quite different from your side that you don't use code for the concepts. But lovely to see your explanation. Both of you explains the concepts beautifully. Thanks.

  • @10199able
    @10199able 2 місяці тому +2

    I like this format!

  • @muhammadumair9074
    @muhammadumair9074 2 місяці тому +2

    Hi Zoran,
    I've been following your work for a while and I'm curious about your audience. Do you find you attract mostly developers who are new to the field(2-5 years of experience), or those with more experience like myself (15+ years)?

    • @zoran-horvat
      @zoran-horvat  2 місяці тому +2

      From analytics, most of the audience are senior programmers.

  • @MrValhallans
    @MrValhallans 2 місяці тому +5

    @zoran-horvat I would love to see your approach to unit testing. E.g. do you follow TDD. What sort of rational do you use on when to right tests and how would that fit into you approach on "Iterative development" (busy with your course on Udemy). I sense many similarities in this gradual progression and emergent design as with red green refactor.

  • @aamirali8114
    @aamirali8114 2 місяці тому

    can you please make a video how to be clear with Oops Concept from our mind and what we have to do to be crystal clear with Oops Concepts.

  • @petervo224
    @petervo224 2 місяці тому

    Thanks for the explanation. I guess I'm quite a slow person, so I'm not able to properly explain it like you do. My thought process whenever facing a question abt LSP of a case usually likes this: "Ok... recall the Rectangle and Square example... now, does this case have anything similar to that example? Yes, no?"

    • @zoran-horvat
      @zoran-horvat  2 місяці тому +1

      Oh, the square and rectangle example is a corner case that spans corners of several programming theories. I would stay away from it when only speaking of LSP.

    • @petervo224
      @petervo224 2 місяці тому

      @@zoran-horvat yeah... with that I can only answer "No" and "Maybe" whenever someone asks me if a case is breaking LSP.

    • @zoran-horvat
      @zoran-horvat  2 місяці тому

      @@petervo224 Actually, you can do more. You can ask for the definition of the interface in terms of the abstract properties it must satisfy and then ask in which way the implementation breaks them.
      It is possible that the implementation is breaking some attributes or not breaking any of them. That is the difference between violating the LSP and not violating it, quite objectively.
      Any other "violation" that causes disagreement might be viewed as a nonfunctional requirement, but not as LSP.

  • @TopKoder
    @TopKoder 2 місяці тому +1

    @zoran-horvat, would you please make a video to demystify the Law of Demeter? That'd be a bang! Thank you.

    • @zoran-horvat
      @zoran-horvat  2 місяці тому +1

      I would have to start with "law of Demeter is not a law". Are you still in?

    • @aflous
      @aflous 2 місяці тому

      Yep, it's a rule, not a law per se

    • @TopKoder
      @TopKoder 2 місяці тому

      @@aflous why? who said that? do you know the cost of violating it?

    • @zoran-horvat
      @zoran-horvat  2 місяці тому +1

      @@TopKoder Actually, I don't know the cost of violating it... Think carefully about your next line.

    • @TopKoder
      @TopKoder 2 місяці тому

      @zoran-horvat sorry, I didn't get the sentiment of the last sentence. Is it humorously intended?
      With regards to the cost of violating LoD. I believe it's increased blast radius (= regression risk, = cost of rework) of any change.

  • @hassansameh3404
    @hassansameh3404 2 місяці тому +1

    The incredible!

  • @nickbarton3191
    @nickbarton3191 2 місяці тому +1

    Still had to read around what class invariants meant. Not being formally trained, still struggle with terminology. I've got the same problem with natural languages, education in UK sucks.
    Otherwise, got you. Is clear.
    Next step, how do I test for adherence to LSP?

    • @zoran-horvat
      @zoran-horvat  2 місяці тому +1

      That is a good question. There is a strong correlation between postconditions and unit tests.

    • @nickbarton3191
      @nickbarton3191 2 місяці тому

      @@zoran-horvat Video coming up? Some code examples? Speaks clearer than abstract terms.

    • @zoran-horvat
      @zoran-horvat  2 місяці тому +2

      @@nickbarton3191 Yes, the video about LSP done in code is currently in the process and should come out soon.

    • @nickbarton3191
      @nickbarton3191 2 місяці тому +1

      @@zoran-horvatSo good, found an oracle that makes practical sense.

  • @LordErnie
    @LordErnie 2 місяці тому

    I like the beard, very calm and well aged look.

    • @zoran-horvat
      @zoran-horvat  2 місяці тому

      I'm young.

    • @LordErnie
      @LordErnie 2 місяці тому

      @zoran-horvat I'm 22 and look better with a light beard. Well aged doesn't mean old

  • @luc9volts
    @luc9volts 2 місяці тому

    The override method will always have different implementation, so what's the point of override in the first place😅 Then like you said, if have same signature and same responses it's not breaking anything 👍🏻

    • @zoran-horvat
      @zoran-horvat  2 місяці тому +3

      Not exactly the same responses. It is a detective game, or the game lawmakers play: Your role as a programmer is to define what's legal and what's not. Everything that is legal must be acceptable by tests, full stop.
      Programmers are often picky, and what they actually end up doing is micromanage their classes.
      A class is free to do (i.e. implement) whatever it finds fit unless that is in the illegal part for the thing it models.
      Once you get to viewing the world through that pair of glasses, you will never want to look back.

    • @luc9volts
      @luc9volts 2 місяці тому

      ​@@zoran-horvat👍🏻👍🏻

  •  2 місяці тому

    The problem with SOLID is that if you have 10 developers in a room, one can tell you all about it, and everyone will agree. If you instead take all the 10 developers in separate rooms and ask them individually, you will have more than 10 explanations about the SOLID principals. People who disagrees with this, is most likely the one person in the first sentence.

    • @zoran-horvat
      @zoran-horvat  2 місяці тому +2

      That may be true in teams where principles are taken religiously. I don't approve of such views on SOLID nor any other set of principles.