Skip to content

Instantly share code, notes, and snippets.

@orhanobut
Last active October 12, 2015 09:49
Show Gist options
  • Save orhanobut/c45de6e1ed8dd1d1b23b to your computer and use it in GitHub Desktop.
Save orhanobut/c45de6e1ed8dd1d1b23b to your computer and use it in GitHub Desktop.
interface Persistence {
void delete();
void add(String value);
String get();
}
class FooBar {
private Persistence persistence;
void persistence(Persistence persistence) {
this.persistence = persistence;
}
private void delete() {
// some different things to handle
if (persistence != null) {
persistence.delete();
}
}
private String get() {
if (persistence != null) {
return persistence.get();
}
return null;
}
private void save(String value) {
if (persistence != null) {
persistence.save(value);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment