Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Null Object Pattern CCE fixed.

...

Code Block
bgColor#ccccff
public interface Log {

  public static final Log NULL = new Log() {
    public void write(String messageToLog) {
      // do nothing
    }
  };

  void write(String messageToLog);
}

class Service {

  private final Log log;

  Service(){
    this.log = Log.NULL;
  }

  // ...
}

Declaring the log reference final ensures that its value is assigned during initialization.

...