Skip to content

Instantly share code, notes, and snippets.

@LH17
Last active April 14, 2018 12:54
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/09b348e69f2d2df1ecc2819d0c6c1d8e to your computer and use it in GitHub Desktop.
Save LH17/09b348e69f2d2df1ecc2819d0c6c1d8e to your computer and use it in GitHub Desktop.
Prototype Design Pattern
// Protocol
protocol Fruit {
func set(price: String?)
func clone() -> Fruit
}
// Class Apple which implements the protocol
class Apple: Fruit {
var count: Int
var price: String?
init(count: Int) {
self.count = count
}
func set(price: String?) {
self.price = price
}
// function definition for cloning the object
func clone() -> Fruit {
return Apple(count: self.count)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment