设计模式:State
针对问题
假设要开发一个工作流程,流程里包括提交、审批、通过、退回几个步骤,一种设计方案如下:
public class Flow
{
//...other fields
int state;
}
public class FlowController
{
public void handleRequest(Flow flow){
if(flow.getState()==0)
{
//do something
}
else if(flow.getState()==1)
{
//do something
}
}
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
public class Flow { //...other fields int state; } public class FlowController { public void handleRequest(Flow flow){ if(flow.getState()==0) { //do something } else if(flow.getState()==1) { //do something |