Liskov Substitution Principle

Поделиться
HTML-код
  • Опубликовано: 18 ноя 2024

Комментарии • 102

  • @mattanderson6672
    @mattanderson6672 3 года назад +6

    Leave it to an Indian guy to take a complicated subject and make it really easy to understand in under 10 min.
    Nice one! Great Explanation!

  • @mrinalraj7166
    @mrinalraj7166 3 года назад +7

    Perfect playlist. thank you so much for your hardwork and time. Please making contribution to the community. You are making a difference

  • @malakawitharana3871
    @malakawitharana3871 Год назад +9

    The Liskov Substitution Principle (LSP) states that an instance of a child class must replace an instance of the parent class without affecting the results that we would get from an instance of the base class itself. This will ensure the class and ultimately the whole application is very robust and easy to maintain and expand, if required¹.
    In the code you provided, it appears that the `PermanentEmployee`, `TemporaryEmployee`, and `ContractEmployee` classes all inherit from the abstract `Employee` class. The `PermanentEmployee` and `TemporaryEmployee` classes also implement the `IEmployeeBonus` interface. The `ContractEmployee` class implements only the `IEmployee` interface.
    The Liskov Substitution Principle is not being implemented in this code because the `ContractEmployee` class does not inherit from the abstract `Employee` class like the other two classes do. This means that it cannot be used interchangeably with instances of the other two classes without affecting the results that we would get from an instance of the base class itself¹.
    I hope this helps! Let me know if you have any other questions.
    Source: Conversation with Bing, 5/21/2023

    • @abhishekk.s2442
      @abhishekk.s2442 10 месяцев назад

      I was wondering how he got the toString implementation in the contract employee class. Did he override it again.

  • @sonalim5338
    @sonalim5338 6 лет назад +17

    CalculateBonus was not implemented. That's the main thing to see how LSP would work, when one of the subclasses doesn't implement it.

  • @atulkumar-bb7vi
    @atulkumar-bb7vi 5 лет назад +18

    It seems more like interface segregation principle rather than LSP?

    • @harshbarnwal1879
      @harshbarnwal1879 3 года назад +2

      No this is LSP, we need to create base class more accurately based on available data and yes it follows ISP as well

  • @maheshreddy7307
    @maheshreddy7307 6 лет назад +20

    So, we are using interface segregation for implementing LISKOV ? please correct me if i'm wrong

    • @haykmkrtchyan7093
      @haykmkrtchyan7093 4 года назад +1

      Same question)) Did you find answer?

    • @maheshreddy7307
      @maheshreddy7307 4 года назад

      @@haykmkrtchyan7093 yes in code project.

    • @haykmkrtchyan7093
      @haykmkrtchyan7093 4 года назад +1

      @@maheshreddy7307 so is it also an interface segregation?

  • @argelpamintuango1956
    @argelpamintuango1956 5 лет назад +3

    This is great video that I thank for. But like other commentators here, I too got confused of some part in the video. First, what happened to CalculateBonus function? Why it is replaced with another function? What if that function is not necessarily required to modify? It might cause to break the application's logic isn't it? I was just thinking that no code changing will be done in that part and make a solution for the given problem.

  • @davidpimentel4996
    @davidpimentel4996 6 лет назад +10

    Great video, thank you! I've learned a lot about the actual reasons behind the SOLID principles.
    I do have one question: why did you have the Employee abstract class implement the IEmployeeBonus interface? If instead you had the PermanentEmployee and TemporaryEmployee classes do so individually, couldn't you have had ContractorEmployee inherit the Employee class and so employ its constructor and ToString methods?

    • @curiossoul
      @curiossoul 2 года назад

      I was about to ask this. Another reason is the naming convention. A contractor is also an employee so must be named correctly.

    • @MohdDanish-kv8ry
      @MohdDanish-kv8ry Год назад +1

      @@curiossoul In this context, you are right. but to help understand LSP it is required to make different interface so that principle is understood correctly.

  • @vineet1034
    @vineet1034 4 года назад +3

    Considering the Quote:
    -- If a program module is using a Base class,
    then the reference to the Base class can be replaced with a Derived class
    without affecting the functionality of the program module
    -- That is no Exception should be thrown by
    subclass
    The Example does not satisfy the Principle, Can you Suggest Another Example ?

  • @eksrikanth06
    @eksrikanth06 6 лет назад +9

    What about CalculateBonus?... at the end

  • @KashishKaushal
    @KashishKaushal 3 года назад +1

    I explained this in an interview and interviewer said that I haven't understood the Principle correctly and that I need to practically implement and understand.
    She said if I just go ahead and override getbonus in contract employee and return 0(which is perfectly valid scenario) then why do I need to segregate Employee class functionality into different interface and seperate out IEmployee bonus.

    • @manish83
      @manish83 7 месяцев назад

      There can be numerous way to do the thing, I don't know what was the interviewer expecations, whether she wanted an example of Liskov principle or just contradict whatever you answered and come up with different stories. I really hate such interviewers who just for belittling ask questions and whether it is even required or used practically most of the time or not.

  • @MayankGupta303
    @MayankGupta303 4 года назад +1

    Your example lands me in my new job.. So many thanks :)

    • @Csharp-video-tutorialsBlogspot
      @Csharp-video-tutorialsBlogspot  4 года назад +1

      Wow....Hearty Congratulations Mayank. Very happy for you. Thank you very much for taking time to share the good news.
      Good luck and all the very best with your new role.

  • @sovanroy9846
    @sovanroy9846 6 лет назад +2

    Thanks a lot Avish.
    It will be great if you show us a real time project using all the design patterns and SOLID principles in future.
    Thank you

    • @avishmsd1651
      @avishmsd1651 6 лет назад +2

      Thank you for watching the video. Really honored with your feedback and Definitely we are planning to come up with a real time project that covers SOLID and DesignPatterns

    • @abdelghanim
      @abdelghanim 5 лет назад

      @@avishmsd1651 Is it the real time project out now?

  • @fundevelopment5223
    @fundevelopment5223 5 лет назад +3

    Hello kudvenkat another solution is derive another abstract class from the abstract class employee for ex bonusEmployee which has the method CalculateBonusSalary() so PermanentEmployee,TemporaryEmployee classes derive from bonusEmployee class and ContractEmployee derive from Employee class.

  • @2SHARP4UIQ150
    @2SHARP4UIQ150 6 лет назад +4

    Your Employee Class don't show your GetMinimumSalary implementation as IEmployee interface required. Also, GetMinimumSalary if that the case, it needs to be virtual so it can be overrode

  • @anilkpathania9183
    @anilkpathania9183 5 лет назад +1

    Appreciate your efforts to help others. try to type code in video as it help for starters otherwise its all good

  • @nikhileshnaregal3643
    @nikhileshnaregal3643 6 лет назад +1

    Hello Avish
    Was able to understand LSP. However, I do have a question related to one of the guideline that says "Client should not know which subtype they are calling". We have created respective child class instances as needed in the main(). Can this be overcome by something called as Factory method design pattern?. Please correct me if I'm wrong, how can we achieve it.
    Also, when are you planning to upload the video for "Dependency Inversion Principle"?
    Thanks,

  • @udayabhanusreeramaraju2977
    @udayabhanusreeramaraju2977 6 месяцев назад

    if we use IEmployee interface for creating Employee object, then we follow LSP but we cannot access bonus methods for permanent employee and temporary employee objects
    if we use Employee class for creating then ContractEmployee object cannot be created (substituted) so LSP not satisfied
    so what is the use of LSP if we want bonus method ?

  • @hansmukhjain3558
    @hansmukhjain3558 3 года назад

    Super explanation!!

  • @kamdemkakengne
    @kamdemkakengne 5 лет назад

    Thank you so much for your explanations! It's very clear!

  • @amitojhahandsomehunk
    @amitojhahandsomehunk 7 месяцев назад

    Sir we have defined CalculateBonus in IEmployeeBonus interface and Employee abstract class... Can we segregate this definitions into one? Or if we do then does this satisfy Liskov Substitution principle?

  • @_akagrawal
    @_akagrawal Месяц назад

    Liskov herself never used the term "Substitute". According to her, it is "behaviour substyping" which states that every subtype should behave the same way it is expected when referencing through parent type as far as methods of parent types are concerned. That means as long as subtypes' implementation of parent type methods are satisfying the characteristics of parent types' methods, it can be called behavioural Subtyping

  • @imadabab
    @imadabab 4 года назад

    Excellent tutorial. Thanks a lot.

  • @xaeropredator
    @xaeropredator 6 лет назад +1

    Also in ContractEmployee Class we need to override ToString method in order to display the employee name correctly, since ContractEmployee Class does not inherit from abstract Employee class...Please correct me if i am wrong :)

    • @prabhattiwari5089
      @prabhattiwari5089 2 года назад

      You are right.
      I think pre-written code has ruined this video.
      Literally, I have watched this number of times to understand.
      Thank you for your efforts. I hope we do not worry about time while typing the code. Since this basically will help understand more easily.

  • @lessknownindeed
    @lessknownindeed 3 года назад

    You are Great!

  • @mahavirsinhpadhiyar864
    @mahavirsinhpadhiyar864 2 года назад

    Amazing explanation sir thank you but I am confused at the end where we missed calling the function CalculateBonus in foreach. What it will do if we call that function?

    • @NeerajKumar-dr3pz
      @NeerajKumar-dr3pz 2 года назад

      It will give you compliation error because calculate bonus is not part of IEmployee.

  • @anilpenumacha6110
    @anilpenumacha6110 6 лет назад

    Thanks alot Avish for videos on SOLID Principles,
    Can you please let me know how you are able to generate the constructor snippet with parameters?
    I have tried ctor and tab, tab shortcut, but it generates only empty constructor with no parameters..
    thanks in advance.

    • @vmguadalupe
      @vmguadalupe 6 лет назад

      In Visual Studio Pro 2017, move cursor to code line of class, then Alt+Enter. You will be presented with Generate Constructor options.

  • @DuelingTreeMike
    @DuelingTreeMike 6 лет назад

    Thanks for the video, however the contract employee received a bonus of 5000 and the rule was that no bonus was to be awarded.
    The DRY (Don’t Repeat Yourself) is slightly infringed upon when bonus percentages are the same - but thats a different story. One solution would be to add a simple read-only property in the employee base class named Bonus and returns 0 - then each inherited implementation of Bonus would be calculated inside the getter. (Thats a hardwired approach that matches your example.)
    I realize that your example is intended to be a simple example to communicate the LSP in C#; however, i believe it’s important to illustrate the S (substitution) helps us and more explanation is required - and you were so close to nailing it!
    Enjoying your videos!

  • @conaxlearn8566
    @conaxlearn8566 4 года назад +1

    What if the requirement is to loop through all employess regardless of type (permanent, temp, contract) and display both minimum salary and bonus if there's any? The "LSP implemented" code in this video is not able to display the bonus salary.

    • @zubairafridi3841
      @zubairafridi3841 3 года назад

      We can check it through is keyword.
      If(employee is Employee e) e.CalcBounus();

  • @sagarjoshi8444
    @sagarjoshi8444 5 лет назад

    Is it plain and simple co-variance or is there something more to it ??

  • @muhammadhamid1961
    @muhammadhamid1961 5 лет назад

    Whats the difference in Interface Segregation and Liskov Substitution ??? both have done some duty bothe have separated or divided in multiple interfaces so this Liskov is also looking same as Segregation

  • @mhasnainadil2875
    @mhasnainadil2875 5 лет назад

    we have inherited iemployee in Employee class which has declaration of CalculateSalary() which must be implemented and also have the same method as an abstract method in Employee class. Its so confusing. What my knowledge says is that we have to implement all the elements of interface but we are initializing the employee name and id in employee class instead using the properties from the iEmployee interface.

  • @subhrajyotisen7153
    @subhrajyotisen7153 4 года назад +1

    why would you extend the IEmployee interface in the Employee abstract class and then inherit it in the other 2 classes? Why not directly extend the corresponding interfaces to the classes? Seems bit of an overkill to me

    • @haykmkrtchyan7093
      @haykmkrtchyan7093 4 года назад

      For me it was the same interface segregation principle + an abstract class)))

  • @vengateshm2122
    @vengateshm2122 4 года назад

    Marvelous

  • @fahadmalik3323
    @fahadmalik3323 3 года назад

    What if the requirement is to loop through all employess regardless of type (permanent, temp, contract) and display both minimum salary and bonus if there's any? The "LSP implemented" code in this video is not able to display the bonus salary. Please answer this question.
    (Copied from the comment section)

  • @henriquefeitosa8027
    @henriquefeitosa8027 4 года назад

    Amazing!!

  • @priyankathakur1595
    @priyankathakur1595 6 лет назад

    Thank you, very well explained

  • @raghavsharma4842
    @raghavsharma4842 5 лет назад

    Hi Buddy, Your explanation of the LS Principle, was possibly one of the best that I saw on RUclips thus far. I am subscribing to your channel and have pressed the Bell icon as well. All the very best man! Thanks for your help!

  • @raguramanmanokaran1824
    @raguramanmanokaran1824 3 года назад

    CalculateBonus is not called in the end ?

  • @lastingfdreedom
    @lastingfdreedom Год назад

    You said it contract employee is not entitled to a bonus. Why didn’t you have CalculateBonus return 0? Then there is no problem.

  • @kidsworld1730
    @kidsworld1730 5 лет назад

    But using IEmployee type list we are not able to access CalculateBonus() method for Permanent and Temporary employee. Then what is the use of creating IEmployee type list? If we need to create 2 type of list Employee Type and IEmployee type every time then i guess its not adhering to LISKOV principle. Please correct me if i am wrong. Also anyone else please give proper solution. Thanks..!!

  • @aashishKr01
    @aashishKr01 6 лет назад

    Please answer the questions in the comment section. It seems incomplete and could land us in embarrassing situations during interviews. Anyways thanks!

  • @suhanimody
    @suhanimody 6 лет назад

    great videos on SOLID .. waiting for Dependency Inversion explanation

  • @piyushprajapati4252
    @piyushprajapati4252 2 года назад

    You have not used CalculateBonus() method to show bonus, as it will give compile time error because IEmployee interface do not have CalculateBonus() method, which means still child class object is not seamlessly replacing parent class. It seems incomplete.

  • @vijaymanda8191
    @vijaymanda8191 2 года назад

    This video is blurred. Could replace good video?

  • @ASHOK_162
    @ASHOK_162 6 лет назад +3

    please add Azure

    • @avishmsd1651
      @avishmsd1651 6 лет назад +1

      Thank you for watching the video. We will try our best to accommodate your suggestion

    • @smukherjee9231
      @smukherjee9231 6 лет назад

      Sure Sir

  • @thegaribovv
    @thegaribovv 2 года назад

    You can still throw runtime error with this implementation too

  • @djangounchained7314
    @djangounchained7314 4 года назад

    I have been watching and coding along in VB2017 in order to grasp the details , unfortunately on this video you went bananas and skipped way too much code, if you are presenting code at least try to show ONCE each part of it, without skipping anything so everyone can follow ...

  • @skh_5678
    @skh_5678 6 лет назад +2

    can not understand properly in 1-2 view. Code example better if you can implement live in video rather than copy/pasting or having ready code. The main purpose i could understand. but better if code example you can give at that moment itself like kudu does.

  • @decentmishra
    @decentmishra 5 лет назад +1

    Please ask Venkat to make the Videos. You are very poor in explaining things..

  • @prafulrane9037
    @prafulrane9037 20 дней назад

    anyone in 2024?

  • @jeganrengasamy7163
    @jeganrengasamy7163 Год назад

    How to call Calculatebonus method by IEmployee object? Calculatebonus method not in use. looks incomplete. Solution : Need to inherit IEmployee in IEmployeeBonus interface. So that we can call both CalculateBonus & GetMinimumSalary methods by using IEmployeeBonus as reference to child class object of PermanentEmployee and TemporaryEmployee.

  • @PavanGarigipati
    @PavanGarigipati 4 года назад

    What is the objective of Liskov ? not clear...

  • @amitdixit2039
    @amitdixit2039 5 лет назад +1

    I think you'r not kudvenkat

  • @iniitu4555
    @iniitu4555 3 года назад

    Why not Employee implements iEmployee ,
    PermanentEmployee & temporaryEmployee inherit from Employee and implement IEmployeeBonus,
    ContractEmployee inherits from Employee

  • @md.shuaibsiddiqui1019
    @md.shuaibsiddiqui1019 6 лет назад

    Sir I request to plzz Upload A Demo Project On Asp.Net Mvc ...Some Think Like e -Commerce Website

  • @ChiefsFanInSC
    @ChiefsFanInSC 5 лет назад

    You should be very careful about creating base classes. If you are developing a business application, base classes are rarely needed.

    • @rahulmathew8713
      @rahulmathew8713 5 лет назад

      In a business application validation can be done by a child class but saving can be done by the base. E.g customer can be standard customer, gold customer and platinum customer. Customer earns points after purchases, so Standard customer will become a gold customer and later he will become platinum, more points means you can replace cash with points to pay off whatever the customer bought on credit. In this case, base class Customer which may be an abstract class can handle the save method, as saving the customer information will not change based on the type but validation on the points will change based on the type of the customer. So derived class of Customer class e.g : StandardCustomer, GoldCustomer can override the abstract method validate.

    • @rahulmathew8713
      @rahulmathew8713 5 лет назад

      Another good area where bases classes are used in Business Application, Repository Pattern decouples Business Logic from Data Access Layer Technology, here also bases classes and interfaces are heavily used.

    • @rahulmathew8713
      @rahulmathew8713 5 лет назад

      With Autofac DI and Automapper, plus repository pattern you can make amazing MVC apps and by using MVVM Prism with WPF u can make enterprise style apps , they all use these base classes and interfaces to achieve it. Rely on Abstraction Not On Concretion is an Object Oriented Principle which will guide you to make decoupled scalable application. This is also achieved by proper use of interfaces and base classes to promote code reuse and decoupling.

  • @avinashsathe2322
    @avinashsathe2322 Год назад

    Not Satisfied with Explanation ...

  • @rahulmathew8713
    @rahulmathew8713 5 лет назад

    At last some real LISkOW Substitution Principle example instead of academic rectangle and square

  • @moiz819
    @moiz819 5 лет назад

    Unable to understand what he is trying to explain, just reading the sentences than explaining.

  • @affluent2022
    @affluent2022 Год назад

    The trainer himself is not sure about difference between Interface segregation, Single Responsibility principle and LSP

  • @chargoy9178
    @chargoy9178 4 года назад

    This example is very bad, doesn't satisfy the principle the second loop you are not calling Bonus method and that is why is running. I saw a lot of comments saying is clear and good, means that they are not understanding the principle.

  • @Real-Hindu-Us88
    @Real-Hindu-Us88 3 года назад

    Still not correct .. I bonus should inherited by permanent employee and temporary employee not employee....

  • @dpynsnyl
    @dpynsnyl Год назад

    This is a partial example of Liskov Substitution, not completely correct.

  • @SumitGupta-vu5ey
    @SumitGupta-vu5ey 6 лет назад +1

    Too hurried....

  • @vkishan2089
    @vkishan2089 4 года назад

    Am I the only one who didn't understand a thing?

  • @TheBgGamers1
    @TheBgGamers1 5 лет назад

    in class ContractEmployee.cs
    // start source code"
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using Implemented_LSP_principle.Interface;
    using Implemented_LSP_principle.Abstract;
    // Тука ще нарушаваме принципа
    namespace Implemented_LSP_principle.Implementation
    {
    public class ContractEmployee : IEmployee
    {
    public int Id { get; set; }
    public string Name { get; set; }
    public ContractEmployee()
    {
    }
    public ContractEmployee(int id, string name)
    {
    this.Id = id;
    this.Name = name;
    }

    public decimal GetMinimumSalary()
    {
    return 50;
    }
    public override string ToString()
    // you don't putt this in .... why ? //
    {
    return string.Format($"ID : {this.Id} Name : {this.Name}");
    }
    }
    }
    "end source code

    • @TheBgGamers1
      @TheBgGamers1 5 лет назад

      Employee ID : 1 Name : John Bonus: 10000.0 Minimum Salary: 100
      Employee ID : 2 Name : Jason Bonus: 5000.00 Minimum Salary: 40
      Employee ID : 1 Name : John Minimum Salary: 100
      Employee ID : 2 Name : Jason Minimum Salary: 40
      Employee Implemented_LSP_principle.Implementation.ContractEmployee Minimum Salar
      y: 50

    • @TheBgGamers1
      @TheBgGamers1 5 лет назад

      Please DO make live content ... or this kind of stuff will be happening ... cheers for video and viewers

  • @dipak1977patel
    @dipak1977patel 6 лет назад

    Instead of duplicating base class members in ContractEmployee. Virtual method approach would be better. ruclips.net/video/okG3cHgFeak/видео.html

  • @dharmeshwarpandey7637
    @dharmeshwarpandey7637 3 года назад

    Little bit messed-up content…

  • @alexk6745
    @alexk6745 3 года назад

    Way too complicated explanation

  • @singhmartand
    @singhmartand 4 года назад

    125567890

  • @rakib4443
    @rakib4443 3 года назад

    bal bujaiso miya

  • @MichaelKingsfordGray
    @MichaelKingsfordGray 2 года назад

    "C"?
    Grow up.

  • @mishrajit
    @mishrajit 2 года назад

    Below is the solution for all of those who are complaining for CalculateBonus is not being implemented at last, and is throwing error. So Please inherit IEmployee form IEmployeeBonus class.
    internal interface IEmployee : IEmployeeBonus
    :)
    Hope it will help someone.