Created
May 13, 2020 03:54
-
-
Save Happytreat/970853649d16a2367bddb23e1d9bdfa1 to your computer and use it in GitHub Desktop.
no override protection example
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
/** | |
* Example from Protocol Oriented Programming - Advanced Swift Programming - raywenderlich.com | |
* https://www.youtube.com/watch?v=ekYdBcl3dzs | |
*/ | |
protocol Geometry { | |
var size: CGSize { get } | |
func boundingBoxArea() -> CGFloat // area -> boundingBoxArea | |
} | |
extension Geometry { | |
// default implementation means no error raised to Circle | |
func boundingBoxArea() -> CGFloat { return size.width * size.height } | |
} | |
extension Circle { | |
// previous area implementation | |
func area() -> CGFloat { return radius * radius * .pi } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment