To avoid NullPointerExceptions I find it useful to provide an immutable dummy implementation of an interface together with the interface. Like this:
public interface Action {
void perform();
public static final Action dummy = new Action() {
public void perform() {
/*nothing*/
}
};
}
Action.dummy
can then be used instead of the evil null
.
Is there a name for this design pattern?