Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Commands {
- private Handlers handlers = new Handlers();
- private void bootstratap() {
- handlers.add(Deactivate.class, command -> deactivate(new ItemRepository(), command));
- handlers.add(Reactivate.class, command -> reactivate(new ItemRepository(), command));
- handlers.add(CheckIn.class, command -> log(command, () -> checkIn(new ItemRepository(), new BarService(), command)));
- }
- public static void deactivate(ItemRepository repository, Deactivate command) {
- }
- public static void reactivate(ItemRepository repository, Reactivate command) {
- }
- public static void checkIn(ItemRepository repository, BarService barService, CheckIn command) {
- }
- public static <T extends Command> void log(T command, Runnable next) {
- System.out.println("Going to call handler for " + command.getClass().getName());
- next.run();
- }
- }
- class Handlers {
- public <T extends Command> void add(Class<T> clazz, CommandHandler<T> handler) {
- }
- }
- interface CommandHandler <T extends Command> {
- void handle(T command);
- }
- class ItemRepository {}
- class BarService {}
- interface Command {}
- class Deactivate implements Command {}
- class Reactivate implements Command {}
- class CheckIn implements Command {}
Add Comment
Please, Sign In to add comment