-
-
Save Juanpe/1128f3fdd8615acecd0af22577c16a10 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
// What | |
protocol LoggerStrategy { | |
func log(_ message: String) | |
} | |
// Who | |
struct Logger { | |
let strategy: LoggerStrategy | |
func log(_ message: String) { | |
strategy.log(message) | |
} | |
} | |
// How | |
struct LowercaseStrategy: LoggerStrategy { | |
func log(_ message: String) { | |
print(message.lowercased()) | |
} | |
} | |
struct UppercaseStratgy: LoggerStrategy { | |
func log(_ message: String) { | |
print(message.uppercased()) | |
} | |
} | |
struct CapitalizedStrategy: LoggerStrategy { | |
func log(_ message: String) { | |
print(message.capitalized) | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment