Skip to content

Instantly share code, notes, and snippets.

@jburwell
Last active December 23, 2015 02:35
Show Gist options
  • Select an option

  • Save jburwell/f5162ad2d2de32c842b3 to your computer and use it in GitHub Desktop.

Select an option

Save jburwell/f5162ad2d2de32c842b3 to your computer and use it in GitHub Desktop.
Null Object Pattern Example
public interface Account extends Nullable {
final static NULL = new NullAccount();
String getName();
String getDescription();
// Whether or not this account can be used to conduct business
boolean isActive();
// Whether or not the internal state of this account is valid
boolean isValid();
private final class NullAccount implements Account {
private NullAccount() {
super();
}
@Override
public boolean isNull() {
return true;
}
@Override
public String getName() {
return "";
}
@Override
public Sting getDescription() {
return "";
}
@Override
public boolean isActive() {
return false;
}
@Override
public boolean isValid() {
return true;
}
@Override
public String toString() {
return "Null Account";
}
}
}
public interface Nullable {
boolean isNull();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment