Created
November 1, 2015 02:16
-
-
Save takaheraw/e6f11edc6713bb734be6 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 ClearMessageChannel { | |
func send(message:String) | |
} | |
protocol SecureMessageChannel { | |
func sendEncryptedMessage(encryptedText:String) | |
} | |
class Communicator { | |
private let clearChannel:ClearMessageChannel | |
private let secureChannel:SecureMessageChannel | |
init(clearChannel:ClearMessageChannel, secureChannel:SecureMessageChannel) { | |
self.clearChannel = clearChannel | |
self.secureChannel = secureChannel | |
} | |
func sendClearTextMessage(message:String) { | |
self.clearChannel.send(message) | |
} | |
func sendSecureMessage(message:String) { | |
self.secureChannel.sendEncryptedMessage(message) | |
} | |
} | |
class LandLine : ClearMessageChannel { | |
func send(message: String) { | |
print("LandLine: \(message)") | |
} | |
} | |
class SecureLandLine : SecureMessageChannel { | |
func sendEncryptedMessage(encryptedText: String) { | |
print("Secure LandLine: \(encryptedText)") | |
} | |
} | |
class Wireless : ClearMessageChannel { | |
func send(message: String) { | |
print("Wireless: \(message)") | |
} | |
} | |
class SecureWireless : SecureMessageChannel { | |
func sendEncryptedMessage(encryptedText: String) { | |
print("Secure Wireless: \(encryptedText)") | |
} | |
} | |
var clearChannel = LandLine() | |
var secureChannel = SecureLandLine() | |
var comms = Communicator(clearChannel: clearChannel, secureChannel: secureChannel) | |
comms.sendClearTextMessage("Hello!") | |
comms.sendSecureMessage("This is a secret") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment