Focus on the chain. A chain. If this node cannot process it, it passes it to the next node.

The key is how do you pass it to the next node?

This node determines which node to pass to.

public class Client
{
    public static void main(String args[])
    {
        Leader objDirector,objManager,objGeneralManager,objViceGeneralManager;

        // Construct the node instance
        objDirector=new Director("Wang Ming");
        objManager=new Manager("Zhao jiang");
        objGeneralManager=new GeneralManager("李波");
        objViceGeneralManager=new ViceGeneralManager("XiaoHong");

        // Set who the next node is
        objDirector.setSuccessor(objManager);
        objManager.setSuccessor(objViceGeneralManager);
        objViceGeneralManager.setSuccessor(objGeneralManager);

        LeaveRequest lr1=new LeaveRequest("Zhang".2);
        objDirector.handleRequest(lr1);

        LeaveRequest lr2=new LeaveRequest("Bill".5);
        objDirector.handleRequest(lr2);

        LeaveRequest lr3=new LeaveRequest("Fifty".15);
        objDirector.handleRequest(lr3);

        LeaveRequest lr4=new LeaveRequest("Daisy".45); objDirector.handleRequest(lr4); }}Copy the code