A better example would be something like this: - You have a function that accepts an Employee object ---- *void CalcSalary(Employee e) { e.CalculateSalary() }* - If you are following LSP, if I pass a subclass object to that function, the program should sill work. Example: *CalcSalary(new PermanentEmployee())*
no it will not as you are breaking the functionality here. See for caluclating a salary we have a particular formula same for bonus and that method will be defined in the parent class. Here in the video he said he is not caluclating just returning the values it means formula will be same for all the employees. But in case for contract employe we cant give bonus and we have to redefine the defination of that bonus method which is wrong.
@@interviewhappy Welcome. And one more thing please make videos on some programmatic/written questions for experienced developer like in SQL and C# LINQ or other type of test questions
This example violates LSP because you're throwing NotImplementedException but you can instead returns 0 bonus for ContractualEmplyeee and avoid the error.
What will happen if we not Override Bonus Method in ContractualEmployee Class? What will happen if we declare only Calculate salary because Bonus method already override in PermanentEmploye Class right!
I have one doubt We can't use the CalculateBonus() method in ContractualEmployee class but it is basically have the method of CalculateBonus() through inheritance. Then my question is how to use CalculateBonus () method in ContractualEmployee class and ContractualEmployee class object?
I am confused you have created object of pEmployee.calculateBonous and saying this follow LSP. Help me to correct if CalculateBonous will be there in PermanentEmployeeClass as it is there in base class then only it follows LSP. LSP : whatever methods is there in parent class that should be there in child class and child class should not change the behavior of parent class object .
Your tutorial is incredibly clear and well-organized! Keep creating more video like this
Thanks buddy and all the best for your career.
Excellent Explaination Sir. Thank you so much for videos on Solid Principles
Thanks Ankita and all the best for your career.
A better example would be something like this:
- You have a function that accepts an Employee object ---- *void CalcSalary(Employee e) { e.CalculateSalary() }*
- If you are following LSP, if I pass a subclass object to that function, the program should sill work. Example: *CalcSalary(new PermanentEmployee())*
What a absolute simple explaination!
Wow wow wow in 7 min you have solved my confusion
Awesome!! understood n will remain permanent in my memory
Hi. Superb explanation. You have explained in clarity and simple words which I hardly found from others
Thank you so much 🙂
this is a better example of interface segregation than LSP
Wow, very simple and best example, Great explanation.
Thanks Bro.
Glad you liked it!
What if you return 0 bonus, instead of throwing exception?, Does it fix Liskov ?
no it will not as you are breaking the functionality here. See for caluclating a salary we have a particular formula same for bonus and that method will be defined in the parent class. Here in the video he said he is not caluclating just returning the values it means formula will be same for all the employees. But in case for contract employe we cant give bonus and we have to redefine the defination of that bonus method which is wrong.
Very good sir keep it up. You are explaining at its best. Please upload repository patterns series after this series
Thanks @ ijaz Will try to do it.
@@interviewhappy Welcome. And one more thing please make videos on some programmatic/written questions for experienced developer like in SQL and C# LINQ or other type of test questions
Very good pls upload more, thanks so much for sharing ur valuable knowledge
Thanks Gaurav and all the best for your career.
Excellent neat and clean explanation
Thanks, glad you found it helpful!
This example violates LSP because you're throwing NotImplementedException but you can instead returns 0 bonus for ContractualEmplyeee and avoid the error.
same question
0 has a value, business perspective we should not provide anything for contract employees
Returning 0 means there is salary component bonus which is wrong. Also think about maintaining this method in long term
Awesome. Really helped. Please create videos for design patterns 😊
It is somewhat similar to interface segregation principle. Because contractaul employee were forced to implement bonus method which it doesn’t need
It is bit similar but not the same.
So we just need to move calculateBonus inside permanentEmployee class right?
we can say that LSP is same as Interface segragation Principal?
Excellent explanation. Thank you
Thanks. Glad you liked it. Wish you all the best for your career.
simple and clear explanation :)
Sir ,Videos really helped me to understand the concepts,Please create azure tutorial as well
just one word : Thanks
Your Welcome @kashif
what are the practical scenarios we need to replace supertype from subtypes?
What will happen if we not Override Bonus Method in ContractualEmployee Class? What will happen if we declare only Calculate salary because Bonus method already override in PermanentEmploye Class right!
I have one doubt
We can't use the CalculateBonus() method in ContractualEmployee class but it is basically have the method of CalculateBonus() through inheritance.
Then my question is how to use CalculateBonus () method in ContractualEmployee class and ContractualEmployee class object?
Sir its humble request plz make video on deep and shallow copy
The above example is for bad design how to fix it?
I am confused you have created object of pEmployee.calculateBonous and saying this follow LSP. Help me to correct if CalculateBonous will be there in PermanentEmployeeClass as it is there in base class then only it follows LSP.
LSP : whatever methods is there in parent class that should be there in child class and child class should not change the behavior of parent class object .
can you make some videos on Architecture interview questions
Why not just return 0 for the bonus?
Well explained. Thanks a lot.
Glad you liked it
great explanation
If we return 0 in the bonus method of contractEmployees method then we wont' voilate.
Good explanation😊
Thanks @ Ravi . Glad You Liked it
Simply WOW 👌👌👌👌
Thanks a lot 😊
yes sure
I feel this is not proper example for LSP
np
please provide your version of LSP sir, so that we all can learn.
Not a correct explanation of LSP
You need to cast child to parent variable
Thankyou!!!!!!
You're welcome! @JSM33TMUSIC
excellent