Skip to content

Instantly share code, notes, and snippets.

@matiasdim
Created December 4, 2020 15:49
Show Gist options
  • Save matiasdim/2172ccdb29ff2e3517b6fbc34452cee2 to your computer and use it in GitHub Desktop.
Save matiasdim/2172ccdb29ff2e3517b6fbc34452cee2 to your computer and use it in GitHub Desktop.
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