void main() {
Log myLog = new Log();
FileLogger myFile = new FileLogger();
ConsoleLogger myConsole = new ConsoleLogger();
myLog.registerLogger(myFile);
myLog.registerLogger(myConsole);
myLog.log("Hello World!!");
myLog.log("Second log event!");
}
class ILogger {
void handleEvent(String event) {}
}
class FileLogger implements ILogger {
void handleEvent(String event) {
print(event);
}
}
class ConsoleLogger implements ILogger {
void handleEvent(String event) {
print(event);
}
}
class Log {
List listeners = [];
void registerLogger(ILogger logger) {
listeners.add(logger);
}
void log(String event) {
for (ILogger logger in listeners) {
logger.handleEvent(event);
}
}
}
Hello World!!
Hello World!!
Second log event!
Second log event!