关于审批单业务中的策略模式运用的问题。
我的业务场景中需要处理一种审批单据,
这种单据根据提出人不同(日入经理和普通职员),
审批者是不一样的。
//伪代码如下:
class ApprovalForm
{
public ApprovalStrategy approvalStrategy;
//提交申请单
public Send()
{
List<Approver> approverList = approvalStrategy.GetApprover();
Send to next Approver ;
}
}
Interface ApprovalStrategy
{
List<Approver> .GetApprover();
}
class ManagerStrategy : ApprovalStrategy
{
public List<Approver> .GetApprover()
{
return Manager's Approver;
}
}
class EmployeeStrategy : ApprovalStrategy
{
public List<Approver> .GetApprover()
{
return Employee's Approver;
}
}
Main()
{
ApprovalForm form = new ApprovalForm();
if ( current user is Manager )
form.approvalStrategy; = new ManagerStrategy ();
if ( current user is Manager )
form.approvalStrategy; = new EmployeeStrategy ();
}
问题是,策略模式虽然帮我在ApprovalForm里面去掉了硬编码的判断,
但是最终我还是要在Mian里面进行硬编码的判断。
开满天机
一只甜甜圈
相关分类