Skip to content

Instantly share code, notes, and snippets.

@iamcrypticcoder
Created March 29, 2018 09:55
Show Gist options
  • Save iamcrypticcoder/39e0ea72d7a07968ef5d2ef273d210f1 to your computer and use it in GitHub Desktop.
Save iamcrypticcoder/39e0ea72d7a07968ef5d2ef273d210f1 to your computer and use it in GitHub Desktop.
class GUIBuilder {
private var platform: String
private var guiFactory: AbstractGUIFactory?
init(platform: String) {
self.platform = platform
}
func initGuiFactory() -> Void {
if nil != guiFactory { return }
if platform == "Windows" { guiFactory = WinFactory() }
else { guiFactory = OSXFactory() }
}
func buildButton() -> Button {
initGuiFactory()
return guiFactory!.createButton()
}
func buildWindow() -> Window {
initGuiFactory()
return guiFactory!.createWindow()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment