Skip to content

Instantly share code, notes, and snippets.

@Happytreat
Created May 13, 2020 03:54
Show Gist options
  • Save Happytreat/970853649d16a2367bddb23e1d9bdfa1 to your computer and use it in GitHub Desktop.
Save Happytreat/970853649d16a2367bddb23e1d9bdfa1 to your computer and use it in GitHub Desktop.
no override protection example
/**
* 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