6k views

### Should rectangle inherit from square? [duplicate]

So, we're all probably familiar with the example provided in most textbooks of the Liskov substitution problem involving a square inheriting from rectangle. The objection to this approach is that ...
625 views

### Backwards inheritance in OOP to model a real-life taxonomy [duplicate]

Is there a way to use the existing features of object oriented programming languages to work around the square/rectangle problem? Can a child be defined in terms of being a more restrictive subset ...
4k views

### Is there a real advantage to dynamic languages? [closed]

First I want to say Java is the only language I ever used, so please excuse my ignorance on this subject. Dynamically typed languages allow you to put any value in any variable. So for example you ...
2k views

### Is there a specific name for the “Square inherits from Rectangle” paradox?

A certain failure of OOP is shown with a class Square inheriting from Rectangle, where logically Square is a specialization of Rectangle and should therefore inherit from it, but everything falls ...
9k views

### How does strengthening of preconditions and weakening of postconditions violate Liskov substitution principle?

I read that Liskov's substitution principle is violated if : Preconditions are strengthened, or Postconditions are weakened But I don't get fully yet how these two points would violate Liskov ...
4k views

### Does this code solve the square/rectangle Liskov Substution Principle example?

I just wanted to check that I understand the LSP correctly and can solve it. I am taking the classic rectangle/square problem and attempting a solution: class Rectangle{ public \$width; public ...
20k views

### Having an inherited function return the derived type instead of the base type

I am writing two classes in C#: A Matrix class that represents a general Matrix with n-by-m dimensions A SquareMatrix class that inherits from Matrix and has the constraint of being n-by-n The ...
460 views

I got into a debate on this question which distilled to if it is a good idea for a specialization of a class to add business rules. Unfortunately this point got trampled in the comments so I'm asking ...