You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In the comment for Liskov Substitution Principle bad example :
function renderLargeRectangles(Rectangle $rectangles): void
{
foreach ($rectangles as $rectangle) {
$rectangle->setWidth(4);
$rectangle->setHeight(5);
$area = $rectangle->getArea(); // BAD: Will return 25 for Square. Should be 20.
$rectangle->render($area);
}
}
$rectangles = [new Rectangle(), new Rectangle(), new Square()];
renderLargeRectangles($rectangles);
For a square the math is right as getArea() should return 25, not 20.
I understand that it implies 20 for 4x5, but this is only for not square and Square is explicitely used.
The example and comment "Should be 20" are confusing.
Edit :
Additionnaly, if the height/width/length are in constructor as seen in acf92a1 and not defined in a function.
You then have :
function renderLargeRectangles(Rectangle $rectangles): void
{
foreach ($rectangles as $rectangle) {
$area = $rectangle->getArea(); // GOOD: Will return 25 for Square.
$rectangle->render($area);
}
}
$rectangles = [new Rectangle(4, 5), new Rectangle(4, 5), new Square(5)];
renderLargeRectangles($rectangles);
And the example becomes correct but I'm being fussy.
The text was updated successfully, but these errors were encountered:
In the comment for Liskov Substitution Principle bad example :
For a square the math is right as getArea() should return 25, not 20.
I understand that it implies 20 for 4x5, but this is only for not square and Square is explicitely used.
The example and comment "Should be 20" are confusing.
Edit :
Additionnaly, if the height/width/length are in constructor as seen in acf92a1 and not defined in a function.
You then have :
And the example becomes correct but I'm being fussy.
The text was updated successfully, but these errors were encountered: