Skip to content

Instantly share code, notes, and snippets.

@LeeKahSeng
Created August 4, 2017 09:32
Show Gist options
  • Save LeeKahSeng/1f48214af2bbeefe77cad6ff99cbfa24 to your computer and use it in GitHub Desktop.
Save LeeKahSeng/1f48214af2bbeefe77cad6ff99cbfa24 to your computer and use it in GitHub Desktop.
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