Last active
April 15, 2018 05:01
-
-
Save LH17/8b16f32569634edb984c609c5809291f to your computer and use it in GitHub Desktop.
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
// 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