Skip to content

Instantly share code, notes, and snippets.

@sdoward
Created November 2, 2022 17:38
Show Gist options
  • Save sdoward/ccd615f0d465c4af9c39115651252502 to your computer and use it in GitHub Desktop.
Save sdoward/ccd615f0d465c4af9c39115651252502 to your computer and use it in GitHub Desktop.
  1. Create a new Implementation of Logger that makes all message uppercase and replace the existing one.
  2. Create a new Implementation of Logger that inherits from the uppercase version. Add new functionality
  3. Create a new LogHandler that inherits from LogHandler. This should allow for the Logger to be changed after the constructor is used
  4. Create a new LogHandler that can accept multiple Loggers and uses all of them to display messages
public interface Logger {
void log(String message);
}
public class LogHandler {
private Logger logger;
public LogHandler(Logger logger) {
this.logger = logger;
}
void handleLog(String message) {
logger.log(message);
}
}
public class Main {
public static void main(String[] args) {
Logger logger = new PlainLogger();
LogHandler logHandler = new LogHandler(logger);
logHandler.handleLog("hello world");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment