How is the Liskov substitution principle used in solid design?

How is the Liskov substitution principle used in solid design?

The Liskov Substitution Principle is the third of Robert C. Martin’s SOLID design principles. It extends the Open/Closed principle and enables you to replace objects of a parent class with objects of a subclass without breaking the application. This requires all subclasses to behave in the same way as the parent class.

Is the Liskov substitution principle redundant with OOP?

At first glance this principle is pretty easy to understand. At second glance it seems redundant with the OOP concept of polymorphism. After all, the whole point of polymorphism is to consume an abstraction without knowing the implementation behind isn’t it?

What does the substitution principle in C # mean?

What this means essentially, is that we should put an effort to create such derived class objects which can replace objects of the base class without modifying its behavior. If we don’t, our application might end up being broken.

How is the substitution principle used in an object oriented program?

At a high level, the LSP states that in an object-oriented program, if we substitute a superclass object reference with an object of any of its subclasses, the program should not break. Say we had a method that used a superclass object reference to do something:

What happens if a subclass violates the LSP?

Every subtype is expected to stick to this contract. If a subclass does not adhere to the superclass’s contract, it’s violating the LSP. This makes sense intuitively – a class’s contract tells its clients what to expect. If a subclass extends or overrides the behavior of the superclass in unintended ways, it would break the clients.

Where can I find the substitution principle in C + +?

So if you don’t have access to the latest compiler you can use https://wandbox.org/ which has preinstalled boost library as well. If I address this in the context of C++, this literally means that functions that use pointers/references to base classes must be able to substitute by its derived classes.