Linked Questions

11 votes
8 answers
4k views

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 < ...
gsmendoza's user avatar
  • 241
3 votes
3 answers
2k views

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 ...
Fendy's user avatar
  • 196
29 votes
9 answers
11k views

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 ...
Geek's user avatar
  • 5,217
24 votes
5 answers
12k views

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 ...
Aviv Cohn's user avatar
  • 21.6k
14 votes
6 answers
958 views

Say I have: interface Thing { GetThing(); } class FastThing : Thing { public int GetThing() { return 1; } } class SlowThing : Thing { public int GetThing() { ...
ConditionRacer's user avatar
7 votes
6 answers
3k views

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, ...
John V's user avatar
  • 4,946
16 votes
1 answer
3k views

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 ...
Songo's user avatar
  • 6,663
2 votes
5 answers
2k views

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 ...
chrisyue's user avatar
  • 161
6 votes
1 answer
4k views

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 ...
Alexis Winters's user avatar
5 votes
2 answers
631 views

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, ...
Andy's user avatar
  • 10.4k
1 vote
5 answers
962 views

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 ...
Tazo Man's user avatar
  • 159
2 votes
2 answers
456 views

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 ...
wcminipgasker2023's user avatar
4 votes
3 answers
534 views

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? ...
John V's user avatar
  • 4,946
3 votes
1 answer
285 views

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 ...
user136627's user avatar
1 vote
2 answers
142 views

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 ...
user3002473's user avatar