Skip to content

Instantly share code, notes, and snippets.

@AppleCEO
Last active August 12, 2021 02:25
Show Gist options
  • Save AppleCEO/3f6983e42099f96362fa82680a755ca4 to your computer and use it in GitHub Desktop.
Save AppleCEO/3f6983e42099f96362fa82680a755ca4 to your computer and use it in GitHub Desktop.
protocol Coffee {
func drink()
}
struct Americano: Coffee {
func drink() {
print("아메리카노를 마십니다.")
}
}
struct Programmer {
private let coffee: Coffee
init(coffee: Coffee) {
self.coffee = coffee
}
func startProgramming() {
self.coffee.drink()
//...
}
}
let americano = Americano()
let programmer = Programmer(coffee: americano)
programmer.startProgramming()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment