Real world example of application of the command pattern

后端 未结 4 2021
我在风中等你
我在风中等你 2021-02-08 01:46

Command pattern can be used to implement Transactional behavior (and Undo).
But I could not find an example of these by googling. I could only find

4条回答
  •  醉梦人生
    2021-02-08 02:05

    public final class Ping implements Callable {
    
      private final InetAddress peer;
    
      public Ping(final InetAddress peer) {
        this.peer = peer;
      }
    
      public Boolean call() {
        /* do the ping */
        ...
      }
    }
    ...
    final Future result
        = executorService.submit(new Ping(InetAddress.getByName("google.com")));
    System.out.println("google.com is " + (result.get() ? "UP" : "DOWN"));
    

提交回复
热议问题