publicclassConcreteHandler3extendsHandler{ @Override publicvoidhandleRequest(int request){ if (request > 7){ System.out.println("ConcreteHandler1: Boss approve: " + request + " days leave."); } } }
// 3. Test publicclassTestChainOfResponsibility{ publicstaticvoidmain(String[] args){ Handler teamLead = new ConcreteHandler1(); Handler manager = new ConcreteHandler2(); Handler boss = new ConcreteHandler3(); teamLead.setSuccessor(manager); manager.setSuccessor(boss);
teamLead.handleRequest(5); } }
// 4. Result ConcreteHandler1: Manager approve: 5 days leave.