Created
October 12, 2015 10:02
-
-
Save orhanobut/0750de3be7ed86adf93e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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