Created
March 25, 2021 20:09
-
-
Save stefanofago73/7668fe65ea01b1761304e364f0ed8fb2 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
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