Approach 2: Instance Methods

  • The logger can be constructed
  • Classes that call the logger use an instance method
public class ImportantProcessHandler {
    private final Logger myLogger;

    public void handleImportantProcess() {
        myLogger.log("Done!");
    }
}

public class Logger {
    public void log(String message) {
        System.out.println(message)
    }
}

24 / 27