Skip to content

Instantly share code, notes, and snippets.

@frankitoy
Forked from BetterProgramming/logMessage.js
Last active January 22, 2020 12:55
Show Gist options
  • Save frankitoy/9ed612b87cf91724519a70e3b9e93490 to your computer and use it in GitHub Desktop.
Save frankitoy/9ed612b87cf91724519a70e3b9e93490 to your computer and use it in GitHub Desktop.
strategy pattern
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