需要以下設計建議所需
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