Skip to content

Instantly share code, notes, and snippets.

@tranhieutt
Created July 12, 2017 10:07
Show Gist options
  • Save tranhieutt/336c0f21cb2db53a450a7bd9627930db to your computer and use it in GitHub Desktop.
Save tranhieutt/336c0f21cb2db53a450a7bd9627930db to your computer and use it in GitHub Desktop.
//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