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
class GUIBuilder { | |
private var platform: String | |
private var guiFactory: AbstractGUIFactory? | |
init(platform: String) { | |
self.platform = platform | |
} | |
func initGuiFactory() -> Void { | |
if nil != guiFactory { return } |
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 Button { | |
func setTitle(_ title: String) -> Void | |
func show() -> Void | |
} | |
protocol Window { | |
func setTitle(_ title: String) -> Void | |
func show() -> Void | |
} |
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
class WinButton: Button { | |
var title: String? | |
func setTitle(_ title: String) -> Void { | |
self.title = title | |
} | |
func show() -> Void { | |
print("Showing Windows style button [Title: \(self.title!)]") | |
} |
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 AbstractGUIFactory { | |
func createButton() -> Button | |
func createWindow() -> Window | |
} |
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
class WinFactory : AbstractGUIFactory { | |
func createButton() -> Button { | |
return WinButton() | |
} | |
func createWindow() -> Window { | |
return WinWindow() | |
} | |
} |
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
class GUIBuilder { | |
private var platform: String | |
private var guiFactory: AbstractGUIFactory? | |
init(platform: String) { | |
self.platform = platform | |
} | |
func initGuiFactory() -> Void { | |
if nil != guiFactory { return } |
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
let guiBuilder: GUIBuilder = GUIBuilder(platform: "Windows") | |
let window: Window = guiBuilder.buildWindow() | |
window.setTitle("Mahbub") | |
window.show() | |
let button: Button = guiBuilder.buildButton() | |
button.setTitle("Connect") | |
button.show() |
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
import Foundation | |
protocol Connection { | |
func makeReady() -> Void | |
func isReady() -> Bool | |
func sendPacket(_ data: String) -> Void | |
} |
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
class EthernetConnection : Connection { | |
func makeReady() { | |
print("Making Ethernet Ready...") | |
} | |
func isReady() -> Bool { | |
return arc4random_uniform(2) == 0 | |
} | |
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
class ThunderboltAdapter { | |
var connection: Connection | |
init(_ connection: Connection) { | |
self.connection = connection | |
} | |
func sendData(_ data: String) { | |
if connection is EthernetConnection { |
OlderNewer