DEV Community

Discussion on: SOLID Principles for OOP

Collapse
 
mdjorov profile image
Miro

I do not agree about the example for Liskov Substitution principle. Order and LargeOrder do not inherit IOrder, they implement it. Big difference. For me a right example is something like:
public class Parent {
void DoSomeWork() {};
}
public class Child : Parent {
void DoSomeOtherWork(){};
}

public void Main()
{
Parent p = new Parent();
Child c = new Child();

SomeFunction(p);
SomeFunction(c);
}

private void SomeFunction(Parent p)
{
p.DOSomeWork();
}
This way no matter what child class of the Parent class is used, the SomeFunction will always work as intended and won't know that the parameter is not a Parent class object, but its child.

Collapse
 
bpkinez profile image
Branislav Petrović

Thanks for this correction! Just what I spotted and I totally agree with your explanation of LSP.