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())*
@@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.
What if you return 0 bonus, instead of throwing exception?, Does it fix Liskov ?
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())*
this is a better example of interface segregation than LSP
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
Awesome!! understood n will remain permanent in my memory
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
What a absolute simple explaination!
Wow, very simple and best example, Great explanation.
Thanks Bro.
Glad you liked it!
Sir its humble request plz make video on deep and shallow copy
Sir ,Videos really helped me to understand the concepts,Please create azure tutorial as well
Very good pls upload more, thanks so much for sharing ur valuable knowledge
Thanks Gaurav and all the best for your career.
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.
simple and clear explanation :)
Awesome. Really helped. Please create videos for design patterns 😊
great explanation
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?
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 .
Excellent explanation. Thank you
Thanks. Glad you liked it. Wish you all the best for your career.
just one word : Thanks
Your Welcome @kashif
The above example is for bad design how to fix it?
Simply WOW 👌👌👌👌
Thanks a lot 😊
Why not just return 0 for the bonus?
Well explained. Thanks a lot.
Glad you liked it
If we return 0 in the bonus method of contractEmployees method then we wont' voilate.
Good explanation😊
Thanks @ Ravi . Glad You Liked it
can you make some videos on Architecture interview questions
yes sure
Thankyou!!!!!!
You're welcome! @JSM33TMUSIC
Not a correct explanation of LSP
You need to cast child to parent variable
I feel this is not proper example for LSP
np
please provide your version of LSP sir, so that we all can learn.
excellent