-
-
Save frankitoy/9ed612b87cf91724519a70e3b9e93490 to your computer and use it in GitHub Desktop.
strategy pattern
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
const strategies = { | |
criticalStrategy, | |
noticeStrategy, | |
catastropheStrategy, | |
} | |
function logMessage(message = "CRITICAL::The system …") { | |
const [level, messageLog] = message.split("::"); | |
const strategy = `${level.toLowerCase()}Strategy`; | |
const output = strategies[strategy](messageLog); | |
} | |
function criticalStrategy(param) { | |
console.log("Critical: " param); | |
} | |
function noticeStrategy(param) { | |
console.log("Notice: " param); | |
} | |
function catastropheStrategy(param) { | |
console.log("Catastrophe: " param); | |
} | |
logMessage(); | |
logMessage("CATASTROPHE:: A big Catastrophe"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment