我现在的类设计是这样的(我已经复制了类层次结构和函数调用。):
Helper* HelperFactory::create(const Advice& advice, const Handler& ah)
{
Helper* result = 0;
switch(advice.getType())
{
case ONE:
case TWO:
{
if(advice.isTradeAdvice())
result = new SimpleHedgeHelper(advice, ah);
else
result = new SimpletradeHelper(advice, ah);
break;
}
case THREE
case FOUR:
case FIVE:
{
if(advice.isTradeAdvice())
result = new ComplexTradeHelper(advice, ah);
else
result = new ComplexHedgeHelper(advice, ah);
break;
}
case SIX:
{
if(!advice.getMsgID())
{
if(advice.isTradeAdvice())
result = new SimpleTradeHelper(advice, ah);
else
result = new SimpleHedgeHelper(advice, ah);
break;
}
else
{
if(advice.isTradeAdvice())
result = new ComplexRateHelper(advice, ah);
else
result = new ComplexHedgeHelper(advice, ah);
break;
}
}
}
我正在尝试用一些基于模板的策略工厂来替换这个逻辑。我之前没有基于 plicly 设计过任何课程 有人可以建议设计应该如何?