OrderHandler.java 523 B

123456789101112131415161718
  1. package responsibilityPattern.handler;
  2. import responsibilityPattern.entity.Order;
  3. public abstract class OrderHandler {
  4. private OrderHandler nextHandler;
  5. public OrderHandler setNextHandler(OrderHandler nextHandler) {
  6. this.nextHandler = nextHandler;
  7. return nextHandler;
  8. }
  9. public void handle(Order order) throws Exception {
  10. if(proceed(order)&&nextHandler != null) {
  11. nextHandler.handle(order);
  12. }
  13. }
  14. abstract boolean proceed(Order order) throws Exception;
  15. }