
Let's understand what is the meaning of "A derived class should correctly implement methods of a base class". (programming, object-oriented) Principle that states that any type having a subtype should be replacable by its. In the above example, we should create another interface for read-only collection without Add() and Remove() methods. Liskov-substitution-principle Definition. LSP suggests that the subtype must be substitutable for the base class or base interface.

The above example violates the Liskov Substitution principle because the MyReadOnl圜ollection class implements the IM圜ollection interface but it throws NotImplementedException for two methods Add() and Remove() because the MyReadOnl圜ollection class is for the read-only collection so you cannot add or remove any item. As the parent class’ speak method doesn’t require a name argument, an instance of the. Although this method returns a string, it needs a name as an argument when called. Its speak method has a parameter name and returns a string. Below is the class Jellyfish, which is a subclass of Animal. Eventually, it turned out that it was one of the easiest and straight forward principles in SOLID principles. I judged the book by its cover, and I convinced myself that I wouldn’t grasp it.

Public class MyReadOnl圜ollection : IM圜ollection The principle of substitution is a fundamental basis of the cost approach to machinery valuation. Violation of the Liskov Substitution Principle. The principle’s name sounded very strange to me.
