-
-
Save lgolubyev/55c85de6ff07401947204352c45cb0be to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Rectangle | |
{ | |
protected double Width = 0; | |
protected double Height = 0; | |
public Drawable Render(double area) | |
{ | |
// ... | |
} | |
public void SetWidth(double width) | |
{ | |
Width = width; | |
} | |
public void SetHeight(double height) | |
{ | |
Height = height; | |
} | |
public double GetArea() | |
{ | |
return Width * Height; | |
} | |
} | |
class Square : Rectangle | |
{ | |
public double SetWidth(double width) | |
{ | |
Width = Height = width; | |
} | |
public double SetHeight(double height) | |
{ | |
Width = Height = height; | |
} | |
} | |
Drawable RenderLargeRectangles(Rectangle rectangles) | |
{ | |
foreach (rectangle in rectangles) | |
{ | |
rectangle.SetWidth(4); | |
rectangle.SetHeight(5); | |
var area = rectangle.GetArea(); // BAD: Will return 25 for Square. Should be 20. | |
rectangle.Render(area); | |
} | |
} | |
var rectangles = new[] { new Rectangle(), new Rectangle(), new Square() }; | |
RenderLargeRectangles(rectangles); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment