Created
December 4, 2020 15:18
-
-
Save matiasdim/512c428317ec20b8da6d228f84c9efe1 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 Circle { | |
var radius: Int | |
init(radius: Int) { | |
self.radius = radius | |
} | |
} | |
class Rectangle { | |
var width: Int | |
var height: Int | |
init(width: Int, height: Int) { | |
self.width = width | |
self.height = height | |
} | |
} | |
class AreaCalculator { | |
func area(shape: AnyObject) -> Double? { | |
if let rectangle = shape as? Rectangle { | |
return Double(rectangle.height * rectangle.width) | |
} else if let circle = shape as? Circle { | |
return Double.pi * Double(circle.radius * circle.radius) | |
} | |
return nil | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment