Created
August 4, 2017 09:32
-
-
Save LeeKahSeng/1f48214af2bbeefe77cad6ff99cbfa24 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 Flyable { | |
/// Limit the speed of flyable | |
var speedLimit: Int { get set } | |
func fly() | |
} | |
extension Flyable { | |
func fly() { | |
print("Fly with speed limit: \(speedLimit)mph") | |
} | |
} | |
class Airplane: Flyable { | |
var speedLimit = 500 | |
} | |
class Helicopter: Flyable { | |
var speedLimit = 150 | |
} | |
class SpeedLimitUpdater { | |
static func reduceSpeedLimit(of flyables: [Flyable], by value: Int) { | |
for var flyable in flyables { | |
flyable.speedLimit -= value | |
} | |
} | |
static func increaseSpeedLimit(of flyables: [Flyable], by value: Int) { | |
for var flyable in flyables { | |
flyable.speedLimit += value | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment