-
-
Save lgolubyev/610f401da16578aeadd9d0af94aaae02 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
abstract class ShapeBase | |
{ | |
protected double Width = 0; | |
protected double Height = 0; | |
abstract public double GetArea(); | |
public Drawable Render(double area) | |
{ | |
// ... | |
} | |
} | |
class Rectangle : ShapeBase | |
{ | |
public void SetWidth(double width) | |
{ | |
Width = width; | |
} | |
public void SetHeight(double height) | |
{ | |
Height = height; | |
} | |
public double GetArea() | |
{ | |
return Width * Height; | |
} | |
} | |
class Square : ShapeBase | |
{ | |
private double Length = 0; | |
public double SetLength(double length) | |
{ | |
Length = length; | |
} | |
public double GetArea() | |
{ | |
return Math.Pow(Length, 2); | |
} | |
} | |
Drawable RenderLargeRectangles(Rectangle rectangles) | |
{ | |
foreach (rectangle in rectangles) | |
{ | |
if (rectangle is Square) | |
{ | |
rectangle.SetLength(5); | |
} | |
else if (rectangle is Rectangle) | |
{ | |
rectangle.SetWidth(4); | |
rectangle.SetHeight(5); | |
} | |
var area = rectangle.GetArea(); | |
rectangle.Render(area); | |
} | |
} | |
var shapes = new[] { new Rectangle(), new Rectangle(), new Square() }; | |
RenderLargeRectangles(shapes); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment