Last active
April 14, 2018 12:54
-
-
Save LH17/09b348e69f2d2df1ecc2819d0c6c1d8e to your computer and use it in GitHub Desktop.
Prototype Design Pattern
This file contains 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
// 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