Created
February 20, 2020 15:37
-
-
Save gelin/92b3260476a568e6531af3c01d7c87f8 to your computer and use it in GitHub Desktop.
SOLID Java 8
This file contains hidden or 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
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