Skip to content

Instantly share code, notes, and snippets.

@gelin
Created February 20, 2020 15:37
Show Gist options
  • Save gelin/92b3260476a568e6531af3c01d7c87f8 to your computer and use it in GitHub Desktop.
Save gelin/92b3260476a568e6531af3c01d7c87f8 to your computer and use it in GitHub Desktop.
SOLID Java 8
public class UpsertTask {
private interface Executor {
void execute() throws TaskExecutionException;
}
private Executor executeMethod;
public void prepare() {
if (/*something*/) {
executeMethod = this::executeInsert;
} else {
executeMethod = this::executeUpdate;
}
}
public void execute() throws TaskExecutionException {
executeMethod.execute();
}
private void executeInsert() throws TaskExecutionException {
// ...
}
private void executeUpdate() throws TaskExecutionException {
// ...
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment