Created
July 12, 2017 10:07
-
-
Save tranhieutt/336c0f21cb2db53a450a7bd9627930db to your computer and use it in GitHub Desktop.
This file contains hidden or 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
//SOLID - O | |
protocol Printable { | |
func printDetails() -> String | |
} | |
class Logger { | |
func printData() { | |
let vehices: [Printable] = [ | |
Car(name: "BWM", color: "Green"), | |
Car(name: "Toyota", color: "Blue"), | |
Car(name: "Honda", color: "Black"), | |
Bicycle(type: "Gongcha"), | |
Bicycle(type: "DingTea") | |
] | |
vehices.forEach {vehices in | |
print(vehices.printDetails()) | |
} | |
} | |
} | |
class Car: Printable { | |
let name: String | |
let color: String | |
init(name: String, color: String) { | |
self.name = name | |
self.color = color | |
} | |
func printDetails() -> String { | |
return "My car \(name) with \(color) color" | |
} | |
} | |
class Bicycle: Printable { | |
let type: String | |
init(type: String) { | |
self.type = type | |
} | |
func printDetails() -> String { | |
return "My bicycle is \(type)" | |
} | |
} | |
let loger = Logger() | |
loger.printData() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment