Last active
March 11, 2017 22:31
-
-
Save cmvandrevala/82a0123045ab2f1db205a0f65c7166c6 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
protocol Logger { | |
func takeAction(flag: Bool) -> Void | |
} | |
class LoggerA: Logger { | |
func takeAction(flag: Bool) { | |
print("LoggerA always prints this message.") | |
} | |
} | |
class LoggerB: Logger { | |
func takeAction(flag: Bool) { | |
if flag { | |
print("LoggerB, the flag is true!") | |
} else { | |
print("LoggerB, the flag is false!") | |
} | |
} | |
} | |
class FakeServer { | |
var loggerList: [Logger] = [LoggerA(), LoggerB()] | |
func run() { | |
someImportantAction() | |
notifyLoggers(flag: true) | |
anotherImportantAction() | |
notifyLoggers(flag: false) | |
} | |
private func someImportantAction() -> Void { | |
print("This is some important action!") | |
} | |
private func anotherImportantAction() -> Void { | |
print("This is another important action!") | |
} | |
private func notifyLoggers(flag: Bool) { | |
for item in loggerList { | |
item.takeAction(flag: flag) | |
} | |
} | |
} | |
var server = FakeServer() | |
server.run(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment