链式处理
Posted gucl
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了链式处理相关的知识,希望对你有一定的参考价值。
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();
以上是关于链式处理的主要内容,如果未能解决你的问题,请参考以下文章