Guest User

Untitled

a guest
Oct 15th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. public class Commands {
  2. private Handlers handlers = new Handlers();
  3.  
  4. private void bootstratap() {
  5. handlers.add(Deactivate.class, command -> deactivate(new ItemRepository(), command));
  6. handlers.add(Reactivate.class, command -> reactivate(new ItemRepository(), command));
  7. handlers.add(CheckIn.class, command -> log(command, () -> checkIn(new ItemRepository(), new BarService(), command)));
  8. }
  9.  
  10. public static void deactivate(ItemRepository repository, Deactivate command) {
  11. }
  12.  
  13. public static void reactivate(ItemRepository repository, Reactivate command) {
  14. }
  15.  
  16. public static void checkIn(ItemRepository repository, BarService barService, CheckIn command) {
  17. }
  18.  
  19. public static <T extends Command> void log(T command, Runnable next) {
  20. System.out.println("Going to call handler for " + command.getClass().getName());
  21. next.run();
  22. }
  23. }
  24.  
  25. class Handlers {
  26. public <T extends Command> void add(Class<T> clazz, CommandHandler<T> handler) {
  27. }
  28. }
  29.  
  30. interface CommandHandler <T extends Command> {
  31. void handle(T command);
  32. }
  33.  
  34. class ItemRepository {}
  35. class BarService {}
  36. interface Command {}
  37. class Deactivate implements Command {}
  38. class Reactivate implements Command {}
  39. class CheckIn implements Command {}
Add Comment
Please, Sign In to add comment