码迷,mamicode.com
首页 > 其他好文 > 详细

链式处理

时间:2019-08-10 17:49:37      阅读:88      评论:0      收藏:0      [点我收藏+]

标签:and   system   bsp   class   cte   protect   oid   public   abs   

public abstract class AbstractHandler {

    private static AbstractHandler handler = new Handler1();

    static {
        handler.setNextHandler(new Handler2())
                .setNextHandler(new Handler3());
    }

    private AbstractHandler nextHandler;

    protected void handle(){
        if(this.nextHandler != null){
            this.nextHandler.handle();
        }
    }

/**
*
* 流程链前置日志
*/
protected String getPreLog() {
return "handle";
}
public AbstractHandler setNextHandler(AbstractHandler nextHandler) { this.nextHandler = nextHandler; return this.nextHandler; } public static AbstractHandler getHandler(){ return handler; } }

 

public class Handler1 extends AbstractHandler{
    @Override
    protected void handle() {
        System.out.println("handle-1");
        super.handle();
    }
}
public class Test {
    public static void main(String[] args) {
        AbstractHandler.getHandler().handle();
    }
}

 

链式处理

标签:and   system   bsp   class   cte   protect   oid   public   abs   

原文地址:https://www.cnblogs.com/gucl/p/11331984.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!