xxxxxxxxxx
This principle states that objects of a derived class should be able to replace objects of the base class without affecting the correctness of the program. In simpler terms, derived classes should be substitutable for their base classes.
Example in React:
Imagine you have a ParentComponent and a ChildComponent. The ChildComponent should be able to replace the ParentComponent without causing unexpected behavior.
// ParentComponent
function ParentComponent(props) {
// Common logic
}
// ChildComponent should be a valid substitute for ParentComponent
function ChildComponent(props) {
// Inherits common logic from ParentComponent
}
xxxxxxxxxx
1. Child function arguments must match function arguments of parent
2. Child function return type must match parent function return type
3. Child pre-conditions cannot be greater than parent function pre-conditions
4. Child function post-conditions cannot be lesser than parent function post-conditions.
5. Exceptions thrown by child method must be the same as or inherit from an exception thrown by the parent method.