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();
}
}
Java中的流模式解析与应用

本文深入探讨了Java设计模式中的流模式,讲解了其基本概念、工作原理及实际应用案例,帮助开发者理解如何在Java中有效地使用流模式提高代码的可读性和效率。
1237

被折叠的 条评论
为什么被折叠?



