需要以下设计建议所需
public class SomeClass
{
public void AuthoriseSmartPhone(...)
{
try
{
Authorise(...)
}
catch(CustomException)
{
throw new CustomException("SmartPhone Message")
}
}
public void AuthoriseFeaturePhone(...)
{
try
{
Authorise(...)
}
catch(CustomException)
{
throw new CustomException("FeaturePhone Message")
}
}
private void Authorise(...)
{
if(manySuchConditionsCheckedHere)
throw new CustomException("");
if(someOtherConditionCheckFails)
throw new YetAnotherException("Common Message to both phones");
}
}
在代码设计建议授权是有很多业务规则检查
的私有方法授权可以为智能手机或功能手机
虽然智能手机和功能电话的规则相同,但是在任何情况下返回的信息都不相同。
目前上面的代码抛出CustomException和同样是捕获并重新抛出。希望得到一些关于如何改善这些代码的设计建议。
可以'Authorise'返回一个bool,您检查以确定您是否在其他方法中抛出异常? – juharr 2013-04-05 15:25:18