Linked Questions
15 questions linked to/from Is this a violation of the Liskov Substitution Principle?
11 votes
8 answers
4k views
How do I design a subclass whose method contradicts its superclass? [duplicate]
How do I design a subclass whose method contradicts its superclass? Let's say we have this example: # Example 1 class Scissor def right_handed? true end end class LeftHandedScissor < ...
3 votes
3 answers
2k views
Does Exception Handling Violates "Program to Abstraction"? [duplicate]
I am talking based on experience with Java and C#. I do not know if other language have different exception handling implementation. In order to achieve loose coupling, we need our code being ...
29 votes
9 answers
11k views
What can go wrong if the Liskov substitution principle is violated?
I was following this highly voted question on possible violation of Liskov Substitution principle. I know what the Liskov Substitution principle is, but what is still not clear in my mind is what ...
24 votes
5 answers
12k views
Is method overriding always a violation of Liskov Substitution Principle?
Overriding a method originally defined in the super class, by definition means this method will do different things when invoked on an object of the base class or an object of the subclass. So does ...
14 votes
6 answers
958 views
Do changes in performance violate the Liskov Substitution Principle?
Say I have: interface Thing { GetThing(); } class FastThing : Thing { public int GetThing() { return 1; } } class SlowThing : Thing { public int GetThing() { ...
7 votes
6 answers
3k views
Liskov Substitution principle - strengthening preconditions
I am a bit confused as for what it really means. In the related questions (Is this a violation of the Liskov Substitution Principle?), it was said that the example clearly violates LSP. But I wonder, ...
16 votes
1 answer
3k views
How to verify the Liskov substitution principle in an inheritance hierarchy?
Inspired by this answer: Liskov Substitution Principle requires that Preconditions cannot be strengthened in a subtype. Postconditions cannot be weakened in a subtype. Invariants of ...
2 votes
5 answers
2k views
Violation of Liskov Substitution Principle?
I've have an animal class class Animal { public function eat(Food $food); } the subclass who inherit it actually cannot support all kinds of Food (Cat can only eat meat): class Cat extends ...
6 votes
1 answer
4k views
What are the examples of breaking Liskov Substitution Principle?
I'm aware that there are 4 ways to violate Liskov Substitution from here. But I'm not sure what these violations would like in practice. Can you show examples of code that breaks the principle for ...
5 votes
2 answers
631 views
Do common MVC frameworks violate the LSP and is there a MVC framework which does not?
You who have worked with a framework implementing the MVC architectural pattern most likely know how these frameworks are usually implemented. They contain a base Controller class, which you extend, ...
1 vote
5 answers
962 views
Liskov Substitution and SRP Principle violation - how best to structure this scenario?
While learning SRP and LSP, I'm trying to improve the design of my code to comply best with both of these principles. I have an employee class that has a calculatePay method on it. Firstly, I believe ...
2 votes
2 answers
456 views
In "Liskov Substitution Principle", are "Preconditions can't be strengthened in a subtype" & "Postconditions can't be weakened in a subtype" the same?
According to Is this a violation of the Liskov Substitution Principle?, as I understand, the top answer currently says the code below is violating "Liskov Substitution Principle": public ...
4 votes
3 answers
534 views
Liskov substitution for voids and weakened preconditions
I am learning a lot about this principle (also thanks to two answers I received here) and would like to elaborate on another point that somebody mentioned. 1) Is the following a violation of LSP? ...
3 votes
1 answer
285 views
How do you keep up with 'requiring new methods in an interface' (Following LSP and adding new methods to interface seems to violate ISP)
I have a game that deals with opening and closing doors and the Door Engine deals with IDoor interface which has Open() and Close() contracts So far so good. the game is tested and works fine. Now a ...
1 vote
2 answers
142 views
Implementing something partially vs providing simple documentation?
I often encounter the following program while programming. There is a "partial" solution to a problem, which provides all the functionality that is necessary, but the documentation explaining said ...