Skip to content

Instantly share code, notes, and snippets.

@sizovs
Last active September 27, 2017 13:51
Show Gist options
  • Save sizovs/4c722960c2ce07e735e175870b1c81b0 to your computer and use it in GitHub Desktop.
Save sizovs/4c722960c2ce07e735e175870b1c81b0 to your computer and use it in GitHub Desktop.
deps.java
class Customer1 {
void change(String password);
}
class Customer2 {
void change(Password password) {
}
}
interface Password {
String raw();
}
class VaultPassword implements Password {
private final Vault vault;
private final Supplier<String> password;
public VaultPassword(Vault vault) {
this.vault = vault;
this.password = Suppliers.memoize(vault::verySecurePassword());
}
@Override
public String raw() {
return password.get();
}
}
class Vault {
public void verySecurePassword() {
// remote call! omg omg omg!
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment