Skip to content

Commit

Permalink
refactor: 擷取IShape介面。
Browse files Browse the repository at this point in the history
  • Loading branch information
LilyLin395135 committed Apr 9, 2023
1 parent e7919e8 commit 07ecb89
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 11 deletions.
9 changes: 2 additions & 7 deletions AreaOfShapeCalulations/Calculator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,9 @@
{
public class Calculator
{
public double GetTotalArea(Rectangle rectangle)
public double GetTotalArea(IShape shape)
{
return rectangle.Area();
}

public double GetTotalArea(Square square)
{
return square.Area();
return shape.Area();
}
}
}
7 changes: 7 additions & 0 deletions AreaOfShapeCalulations/IShape.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace AreaOfShapeCalulations
{
public interface IShape
{
double Area();
}
}
4 changes: 2 additions & 2 deletions AreaOfShapeCalulations/Rectangle.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace AreaOfShapeCalulations
{
public class Rectangle
public class Rectangle : IShape
{
private readonly double _height;
private readonly double _width;
Expand All @@ -11,7 +11,7 @@ public Rectangle(double height, double width)
_width = width;
}

internal double Area()
public double Area()
{
return _height * _width;
}
Expand Down
4 changes: 2 additions & 2 deletions AreaOfShapeCalulations/Square.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace AreaOfShapeCalulations
{
public class Square
public class Square : IShape
{
private readonly double _length;

Expand All @@ -9,7 +9,7 @@ public Square(double length)
_length = length;
}

internal double Area()
public double Area()
{
return _length * _length;
}
Expand Down

0 comments on commit 07ecb89

Please sign in to comment.