Liskov Substitution Principle
Barbara Liskov introduced this principle in a 1987 conference keynote address called "Data abstraction and hierarchy". Liskov and Jeannette Wing developed the principle and it was officially published in 1993
"Functions that use pointers or references to base classes must be able to use objects of derived classes without knowing it"
Other wordings for this principle are:
"Objects of a superclass shall be replaceable with objects of its subclasses without breaking the application"
According to Uncle Bob, "The implementation of an interface must never violate the contract between that interface and its users.". In simple words, each class implementation, either inheriting from an interface or a parent class, should respect previous implementations.
Here's an example.
interface IPlant {
void AbsorbNutrients();
}
public class Plant: IPlant {
public void AbsorbNutrients()
{
// do nothing
}
}
To make it sweet and short, you are not supposed to change (or leave unimplemented) behavior (or expected implementations) given by your interfaces or your parent classes.`
Does this means that if I inherit from a class that has a virtual method, I should not override that method?.
You can, but always consider if you should to include a call to the parent class method to ensure the expected behavior of the program.