Skip to content

Instantly share code, notes, and snippets.

@orhanobut
Created October 12, 2015 10:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save orhanobut/0750de3be7ed86adf93e to your computer and use it in GitHub Desktop.
Save orhanobut/0750de3be7ed86adf93e to your computer and use it in GitHub Desktop.
interface Persistence {
void delete();
void add(String value);
String get();
}
static class EmptyPersistence implements Persistence {
@Override void delete(){
}
@Override void add(String value) {
}
@Override String get() {
return null;
}
}
class FooBar {
private Persistence persistence = new EmptyPersistence();
void persistence(Persistence persistence) {
this.persistence = persistence;
}
private void delete() {
...
persistence.delete();
}
private String get() {
return persistence.get();
}
private void save(String value) {
persistence.save(value);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment