Created
December 4, 2020 15:49
-
-
Save matiasdim/2172ccdb29ff2e3517b6fbc34452cee2 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
protocol GeometricFigure { | |
func area() -> Double | |
} | |
class Circle: GeometricFigure { | |
var radius: Double | |
init(radius: Double) { | |
self.radius = radius | |
} | |
func area() -> Double { | |
return Double.pi * radius * radius | |
} | |
} | |
class Rectangle: GeometricFigure { | |
var width: Double | |
var height: Double | |
init(width: Double, height: Double) { | |
self.width = width | |
self.height = height | |
} | |
func area() -> Double { | |
return width * height | |
} | |
} | |
class AreaCalculator { | |
func area(figure: GeometricFigure) -> Double { | |
return figure.area() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment