【发布时间】:2010-06-13 02:10:15
【问题描述】:
我有一个类,它有一个调用大量私有方法的大方法。我想我想将这些私有方法提取到他们自己的类中,因为它们包含业务逻辑,我认为它们应该是公共的,因此可以进行单元测试。
以下是代码示例:
public void handleRow(Object arg0) {
if (continueRunning){
hashData=(HashMap<String, Object>)arg0;
Long stdReportId = null;
Date effDate=null;
if (stdReportIds!=null){
stdReportId = stdReportIds[index];
}
if (effDates!=null){
effDate = effDates[index];
}
initAndPutPriceBrackets(hashData, stdReportId, effDate);
putBrand(hashData,stdReportId,formHandlerFor==0?true:useLiveForFirst);
putMultiLangDescriptions(hashData,stdReportId);
index++;
if (stdReportIds!=null && stdReportIds[0].equals(stdReportIds[1])){
continueRunning=false;
}
if (formHandlerFor==REPORTS){
putBeginDate(hashData,effDate,custId);
}
//handle logic that is related to pricemaps.
lstOfData.add(hashData);
}
}
我应该使用什么设计模式来解决这个问题?
【问题讨论】:
-
总是让自己有答案是“无”的可能性。设计模式本身并不是设计,您不能只为遇到的每个设计问题从菜单中选择一个。
-
在添加类之前,你应该问自己,“这个类的实例将代表什么?”如果答案是它只是一个代码容器,那么你只是将类用作命名空间。
标签: design-patterns