Skip to content

Instantly share code, notes, and snippets.

@LH17
Last active April 15, 2018 05:01
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/8b16f32569634edb984c609c5809291f to your computer and use it in GitHub Desktop.
Save LH17/8b16f32569634edb984c609c5809291f to your computer and use it in GitHub Desktop.
// Abstract Factory
protocol FurnitureFactory {
static func createTable() -> Table
static func createChair() -> Chair
}
// Abstract product Table
protocol Table {
func count() -> Int
}
// abstarct product CHair
protocol Chair {
func count() -> Int
}
// concrete factory
class Factory: FurnitureFactory {
static func createChair() -> Chair {
return MyChair()
}
static func createTable() -> Table {
return MyTable()
}
}
// concrete product MyChair conforms to Chair
private class MyChair: Chair {
func count() -> Int {
return 4
}
}
// concrete product MyTable conforms to Table
private class MyTable: Table {
func count() -> Int {
return 1
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment