标签:
public abstract classAbstractLogger{
publicstaticint INFO =1;
publicstaticint DEBUG =2;
publicstaticint ERROR =3;
protectedint level;
//拦截类中聚合责任链中的下一个拦截类
protectedAbstractLogger nextLogger;
publicvoid setNextLogger(AbstractLogger nextLogger)//设置责任链中的下一个拦截类
{
this.nextLogger = nextLogger;
}
publicvoid logMessage(int level,String message)
{
if(this.level <= level){ //条件判断是否适合自己处理
write(message);
}
if(nextLogger !=null){ //把信息传递到责任链的下一个拦截类处理
nextLogger.logMessage(level, message);
}
}
abstract protectedvoid write(String message);
}
标签:
原文地址:http://www.cnblogs.com/Doing-what-I-love/p/5621168.html