我有RiskReport類型,它根據預定的公式從IReportRepository獲取數據,操縱數據,並計算風險。
有人可能會說,RiskReport類型應該以確切格式獲取數據,而不是執行數據操作。 RiskReport應該只關心如何根據公式計算數據,而IReportRepository應該只返回RiskReport類所需的數據。
IReportRepository和RiskReport之間應該引入一個新類嗎?因爲目前從IReportRepository返回的數據被操縱爲所需的格式來計算風險。
class RiskReport
{
private IReportRepository reportRepository;
public RiskReport(IReportRepository reportRepository)
{
this.reportRepository = reportRepository;
}
public decimal CalculateDataBasedOnFormula()
{
var result = from d in reportRepository.GetReportRelatedData()
group d by d.Id into dgp //potentially complex grouping
select new
{
TotalPage = dgp.Sum(x=>x.Pages) //potentially complex projection
};
decimal risk= //use the result variable to calculate data based on complex formula not shown here
return risk;
}
}
interface IReportRepository
{
IEnumerable<ReportRelatedData> GetReportRelatedData();
}
public class ReportRepository: IReportRepository
{
public IEnumerable<ReportRelatedData> GetReportRelatedData()
{
//return data from underlying data source
return new BindingList<ReportRelatedData>();
}
}
public class ReportRelatedData
{
public int Id { get; set; }
public int Name { get; set; }
public int Pages { get; set; }
//... more properties here
}
任何想法,將不勝感激!
謝謝您的建議。我將報告類型更改爲RiskReport類型,是否會影響您的建議? – Pingpong 2012-04-24 07:34:51