Skip to content

Instantly share code, notes, and snippets.

@stefanofago73
Created March 25, 2021 20:09
Show Gist options
  • Save stefanofago73/7668fe65ea01b1761304e364f0ed8fb2 to your computer and use it in GitHub Desktop.
Save stefanofago73/7668fe65ea01b1761304e364f0ed8fb2 to your computer and use it in GitHub Desktop.
import java.util.List;
import static java.util.stream.Collectors.toList;
class Command {
}
interface CommandHandler {
public Result handle(Command cmd);
}
enum Result {
OK,KO;
}
class DomainHandler implements CommandHandler {
@Override
public Result handle(Command cmd) {
//try{
return Result.OK;
//}catch(Exception exc){
// return Result.KO;
//}
}
}
public class ExecutionFlow {
public static void main(String[] args) {
List<Command> cmds = List.of(new Command(),new Command(),new Command());
DomainHandler handler = new DomainHandler();
// managing void return type
cmds.stream().forEach(handler::handle);
// using a placeholder return type
List<Result> collect = cmds.stream().map(handler::handle).collect(toList());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment