class ConsoleLogger {
log(message) {
console.log(message);
}
}
class AlertLogger {
log(message) {
alert(message);
}
}
class Logger {
constructor(logger) {
this.logger = logger;
}
log(message) {
throw new Error('Not implemented!');
}
}
class InfoLogger extends Logger {
constructor(message, logger) {
super(logger);
this.message = message;
}
log() {
this.logger.log(`INFO: ${this.message}`);
}
}
class ErrorLogger extends Logger {
constructor(message, logger) {
super(logger);
this.message = message;
}
log() {
this.logger.log(`ERROR: ${this.message}`);
}
}
const consoleLogger = new ConsoleLogger();
const alertLogger = new AlertLogger();
const infoLogger = new InfoLogger('데이터', consoleLogger);
const errorLogger = new ErrorLogger('무언가 잘못된것 같은데요?!', alertLogger);
infoLogger.log(); // "INFO: 데이터"
errorLogger.log(); // "ERROR: 무언가 잘못된것 같은데요?!"