Skip to content

Instantly share code, notes, and snippets.

@LH17
Last active April 15, 2018 06:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LH17/165fe4d2803d2cf66e8f3e99c1d79214 to your computer and use it in GitHub Desktop.
Save LH17/165fe4d2803d2cf66e8f3e99c1d79214 to your computer and use it in GitHub Desktop.
// protocol for creating a product
protocol ShoeShop {
func produceShoe()
}
// class that conforms to ShoeShop protocol
class Nike: ShoeShop {
func produceShoe() {
print("Shoe Produced")
}
}
// class that is initialsed with the object that conforms to ShoeShop protocol
class Director {
let shoeShop: ShoeShop
// instantiation
init(shoeShop: ShoeShop) {
self.shoeShop = shoeShop
}
func produce() {
shoeShop.produceShoe()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment