Created
March 8, 2018 19:38
-
-
Save joanmolinas/29a215a7b3e634663213c2002d9579ec to your computer and use it in GitHub Desktop.
This file contains hidden or 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 RectangleField { | |
var width: Float = 0 | |
var height: Float = 0 | |
var area: Float { | |
return width * height | |
} | |
} | |
class SquareField: RectangleField { | |
override var area: Float { | |
return width * width | |
} | |
} | |
func printField(field: Field) { | |
print(field.area) | |
} | |
let field = RectangleField() | |
field.width = 2 | |
field.height = 4 | |
printField(field: field) // 8 | |
let squareField = SquareField() | |
squareField.width = 2 | |
squareField.height = 4 | |
printField(field: squareField) // 4 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment