Answer the question
In order to leave comments, you need to log in
Why is the rectangle not an instance of the square class?
I’m watching a webinar on OOP, and it talks about class inheritance using the example of a square and a rectangle Saying
what is better for the progenitor ,
a square or a rectangle to each
other supposedly the area cannot be calculated equally for a square and a rectangle
Why not to calculate, if for a square you can multiply the width by the height, that for a rectangle
It seems to me that the square is suitable for the ancestor of the rectangle in the hierarchy, but on the contrary,
for OOP objects that should be interchangeable?
set_width()
set_height()
calculate_area()
after all, the same properties and methods
can be because both a square and a rectangle can only be objects of the quadrilateral class?
Answer the question
In order to leave comments, you need to log in
I think that if you set the length and width of a rectangle to be different in size, then the condition that it is a square will not be fulfilled
I think what was meant was that a rectangle is a broader concept than a square.
In your example, one of the principles of SOLID (Barbara Liskov's Substitution Principle) is violated.
Here is the material in which your example is understood.
Also there you can generally get a lot of information on other principles.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question