Liskov Substitution Principle

แชร์
ฝัง
  • เผยแพร่เมื่อ 28 ก.ย. 2024
  • In this video we will learn
    1. Liskov Substitution Principle
    2. Implementation guidelines of Liskov Substitution Principle
    3. And will implement this Principle with a simple example
    Healthy diet is very important for both body and mind. We want to inspire you to cook and eat healthy. If you like Aarvi Kitchen recipes, please support by sharing, subscribing and liking.
    / @aarvikitchen5572
    In the first video of SOLID Introduction we have understood that L in the SOLID is acronym for Liskov Substitution Principle which is also known as LSP.
    Definition : Substitutability is a principle in object-oriented programming and it states that, in a computer program, if S is a Subtype of T, then objects of type T may be replaced with objects of type S
    1. Which means, Derived types must be completely substitutable for their base types
    2. More formally, the Liskov substitution principle (LSP) is a particular definition of a subtyping relation, called (strong) behavioral subtyping
    3. This Principle is introduced by Barbara Liskov in 1987 during her conference address on Data abstraction and hierarchy
    4. This principle is just an extension of the Open Close Principle
    The examples used in this session are related to the open closed principle. Hence we request you to watch the Open Closed Principle tutorial before proceeding.
    Implementation guidelines : In the process of development we should ensure that
    1. No new exceptions can be thrown by the subtype unless they are part of the existing exception hierarchy.
    2. We should also ensure that Clients should not know which specific subtype they are calling, nor should they need to know that. The client should behave the same regardless of the subtype instance that it is given.
    3. And last but not the least, New derived classes just extend without replacing the functionality of old classes
    In the previous session as part of the Open closed Principle implementation we have created different employee classes to calculate bonus of the employee. From the employee perspective we have implemented the Open closed principle.
    Now if you take a look at the main program, we have created Employee objects which consists of both permanent and contract employee.
    If you take a closer look at this program the Derived types which are Permanent and TemporaryEmployee have completely substituted the base type employee class.
    So, based on the Liskov substitution principle we have achieved LSP by ensuring that Derived types are completely substitutable for their base types.
    Also, notice the main program, without using the subtypes we are calculating the bonus of the employee from the base class type itself. Hence, we are satisfying the Liskov substitution principle.
    That means along with the Open Closed Principle we have partially implemented the LSP.
    Also, I can state that this implementation is not adhering to guide lines of Liskov principle
    To understand why it’s not adhering to the Liskov Principle, Let’s assume that we need to have a Contract Employee as one of the employee category. A point to note here is a contract employee is not eligible for any bonus calculation and post implementing the Employee class we end up throwing exception at the runtime in the caclculatebonus() method. This violates the Liskov Substitution Principle.
    Hence, Please follow the below code which addresses this issue. Also, we recommend to watch our video tutorials for complete guidance and understanding of the code.
    The code is available on our blog at the following link.
    csharp-video-tu...
    Text version of the video
    csharp-video-tu...
    Slides
    csharp-video-tu...
    SOLID Design Principles Tutorial
    • SOLID Design Principle...
    SOLID Design Principles Text Articles & Slides
    csharp-video-tu...
    All Dot Net and SQL Server Tutorials in English
    www.youtube.co...
    All Dot Net and SQL Server Tutorials in Arabic
    / kudvenkatarabic

ความคิดเห็น • 100

  • @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.

  • @malakawitharana3871
    @malakawitharana3871 ปีที่แล้ว +8

    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 8 หลายเดือนก่อน

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

  • @MayankGupta303
    @MayankGupta303 3 ปีที่แล้ว +1

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

    • @Csharp-video-tutorialsBlogspot
      @Csharp-video-tutorialsBlogspot  3 ปีที่แล้ว +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.

  • @henriquefeitosa8027
    @henriquefeitosa8027 4 ปีที่แล้ว

    Amazing!!

  • @udayabhanusreeramaraju2977
    @udayabhanusreeramaraju2977 4 หลายเดือนก่อน

    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 ?

  • @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.

  • @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();

  • @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.

  • @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

  • @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.

  • @md.shuaibsiddiqui1019
    @md.shuaibsiddiqui1019 6 ปีที่แล้ว

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

  • @dpynsnyl
    @dpynsnyl ปีที่แล้ว

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

  • @decentmishra
    @decentmishra 5 ปีที่แล้ว +1

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

  • @singhmartand
    @singhmartand 4 ปีที่แล้ว

    125567890

  • @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.

  • @rakib4443
    @rakib4443 3 ปีที่แล้ว

    bal bujaiso miya

  • @alexk6745
    @alexk6745 3 ปีที่แล้ว

    Way too complicated explanation

  • @mattanderson6672
    @mattanderson6672 3 ปีที่แล้ว +5

    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!

  • @maheshreddy7307
    @maheshreddy7307 6 ปีที่แล้ว +20

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

    • @haykmkrtchyan7093
      @haykmkrtchyan7093 3 ปีที่แล้ว +1

      Same question)) Did you find answer?

    • @maheshreddy7307
      @maheshreddy7307 3 ปีที่แล้ว

      @@haykmkrtchyan7093 yes in code project.

    • @haykmkrtchyan7093
      @haykmkrtchyan7093 3 ปีที่แล้ว +1

      @@maheshreddy7307 so is it also an interface segregation?

  • @atulkumar-bb7vi
    @atulkumar-bb7vi 5 ปีที่แล้ว +17

    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

  • @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 ?

  • @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

  • @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.

  • @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

  • @eksrikanth06
    @eksrikanth06 6 ปีที่แล้ว +10

    What about CalculateBonus?... at the end

  • @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.

  • @amitojhahandsomehunk
    @amitojhahandsomehunk 5 หลายเดือนก่อน

    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?

  • @chargoy9178
    @chargoy9178 3 ปีที่แล้ว

    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.

  • @iniitu4555
    @iniitu4555 3 ปีที่แล้ว

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

  • @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 5 หลายเดือนก่อน

      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.

  • @Real-Hindu-Us88
    @Real-Hindu-Us88 3 ปีที่แล้ว

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

  • @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 3 ปีที่แล้ว

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

  • @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.

  • @thegaribovv
    @thegaribovv ปีที่แล้ว

    You can still throw runtime error with this implementation too

  • @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.

  • @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

  • @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. th-cam.com/video/okG3cHgFeak/w-d-xo.html

  • @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)

  • @vijaymanda8191
    @vijaymanda8191 2 ปีที่แล้ว

    This video is blurred. Could replace good video?

  • @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..!!

  • @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?

  • @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,

  • @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.

  • @muhammadhamid1961
    @muhammadhamid1961 4 ปีที่แล้ว

    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

  • @avinashsathe2322
    @avinashsathe2322 11 หลายเดือนก่อน

    Not Satisfied with Explanation ...

  • @aashishKr01
    @aashishKr01 5 ปีที่แล้ว

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

  • @dharmeshwarpandey7637
    @dharmeshwarpandey7637 3 ปีที่แล้ว

    Little bit messed-up content…

  • @amitdixit2039
    @amitdixit2039 5 ปีที่แล้ว +1

    I think you'r not kudvenkat

  • @vkishan2089
    @vkishan2089 4 ปีที่แล้ว

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

  • @SumitGupta-vu5ey
    @SumitGupta-vu5ey 6 ปีที่แล้ว +1

    Too hurried....

  • @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.

  • @PavanGarigipati
    @PavanGarigipati 4 ปีที่แล้ว

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

  • @sagarjoshi8444
    @sagarjoshi8444 5 ปีที่แล้ว

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

  • @MichaelKingsfordGray
    @MichaelKingsfordGray 2 ปีที่แล้ว

    "C"?
    Grow up.

  • @raguramanmanokaran1824
    @raguramanmanokaran1824 3 ปีที่แล้ว

    CalculateBonus is not called in the end ?

  • @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.

  • @kamdemkakengne
    @kamdemkakengne 4 ปีที่แล้ว

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

  • @imadabab
    @imadabab 4 ปีที่แล้ว

    Excellent tutorial. Thanks a lot.

  • @hansmukhjain3558
    @hansmukhjain3558 3 ปีที่แล้ว

    Super explanation!!

  • @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.

  • @vengateshm2122
    @vengateshm2122 4 ปีที่แล้ว

    Marvelous

  • @lessknownindeed
    @lessknownindeed 3 ปีที่แล้ว

    You are Great!

  • @priyankathakur1595
    @priyankathakur1595 6 ปีที่แล้ว

    Thank you, very well explained

  • @affluent2022
    @affluent2022 ปีที่แล้ว

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

  • @raghavsharma4842
    @raghavsharma4842 5 ปีที่แล้ว

    Hi Buddy, Your explanation of the LS Principle, was possibly one of the best that I saw on TH-cam 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!

  • @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!

  • @suhanimody
    @suhanimody 6 ปีที่แล้ว

    great videos on SOLID .. waiting for Dependency Inversion explanation

  • @0800773796
    @0800773796 6 ปีที่แล้ว +2

    "New derived class just extend without replacing the functionality of old class". Does it mean 'virtual override' keyword against this principle?

    • @HeWhoWritesCode
      @HeWhoWritesCode 4 ปีที่แล้ว

      No, the functionality still remains the same, just the definition of functionality is different.

  • @mishrajit
    @mishrajit ปีที่แล้ว

    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.