java commons-chain_Apache commons chain简介和简单实现

apache commons chain 提供了对CoR模式的基础支持。。CoR模式,是Chain of Responsebility的缩写。CommonsChain实现了Chain of Responsebility和Command模式,其中的Catalog + 配置文件的方式使得调用方和Command的实现方的耦合度大大的降低,提高了灵活性。

使用Apachecommons chain,需要将commons-chain.jar放入你的classpath,目前最新的版本是1.2。

从使用的角度来看,和工作流(workflow)非常相似。

一个使用Apachecommons chain的简单的例子:

packagetest.ffm83.commons.chain;

importorg.apache.commons.chain.Command;

importorg.apache.commons.chain.Context;

importorg.apache.commons.chain.impl.ChainBase;

importorg.apache.commons.chain.impl.ContextBase;

/**

* 通过commons chain 进行任务链的处理

* @author 范芳铭

*/

publicclass CommandChain  extends ChainBase{

//增加命令的顺序也决定了执行命令的顺序

public CommandChain(){

addCommand( new Command1());

addCommand( new Command2());

addCommand( new Comman


本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!

相关文章

立即
投稿

微信公众账号

微信扫一扫加关注

返回
顶部