Java 设计模式 之 流模式
http://www.verejava.com/?id=16999114235569
package com.flow.theory;
public class Test
{
public static void main(String[] args)
{
Context ctx=new Context();
ctx.setFlow(new ApplyFlow());
ctx.process();
ctx.setFlow(new VerfiyFlow());
ctx.process();
ctx.setFlow(new ApproveFlow());
ctx.process();
}
}
package com.flow.theory;
public interface Flow
{
public void action();
}
package com.flow.theory;
public class VerfiyFlow implements Flow
{
@Override
public void action()
{
System.out.println("审核");
}
}
package com.flow.theory;
public class ApplyFlow implements Flow
{
@Override
public void action()
{
System.out.println("申请");
}
}
package com.flow.theory;
public class ApproveFlow implements Flow
{
@Override
public void action()
{
System.out.println("审批");
}
}
package com.flow.theory;
public class Context
{
private Flow flow;
public void setFlow(Flow flow)
{
this.flow=flow;
}
public void process()
{
flow.action();
}
}