-
-
Save philsquared/86763cd8639c85cc117622ad2f0a2a5f 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
protocol Square { | |
var size : Float{ get } | |
} | |
protocol Circle { | |
var radius : Float{ get } | |
} | |
class SquarePeg : Square { | |
let _size : Float | |
init( size : Float ) { _size = size } | |
var size : Float { get{ return _size } } | |
} | |
class RoundHole { | |
func fit( _ circleShapedThing : Circle ) { | |
print( "fit, with a radius of: \(circleShapedThing.radius)") | |
} | |
} | |
// ---------- | |
extension SquarePeg : Circle { | |
var radius : Float{ get { return (_size*size*2).squareRoot() } } | |
} | |
let squarePeg = SquarePeg( size: 42.0 ) | |
let hole = RoundHole() | |
hole.fit( squarePeg ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment