我們正在使用Model-View-Presenter被動視圖策略構建我們的軟件。在我們的軟件上,我們有一個報告和不同類型的圖表。因此,我們必須對圖表的抽象類的功能,所有的圖表將實施:如何在MVP中爲抽象模型創建視圖和演示者
abstract class AbstractChart
{
...
}
然後我們有具體類(模型),可以說,條形圖和餅圖:
class BarChart: AbstractChart
{
...
}
class PieChart: AbstractChart
{
...
}
報表可以包含不同圖表的種類。
class Report
{
public List<AbstractChart> Charts {get; set; }
...
}
所以,我們必須在報表上繪製不同的圖表的一個問題:
class ReportPresenter
{
Report _report;
ReportView _view;
...
FillReportView(Report report)
{
foreach(AbstractChart chart in _report.Charts)
{
// Here is the problem: How do we create correct
// view and presenter for abstract chart? We need to
// create them, so we can add chart view to _view.
}
}
}
有沒有原因,你不使用MVVM與WPF? – 2012-02-28 14:00:02
我們嘗試過MVVM,但雖然它看起來非常好,但它證明了我們的需求太複雜。 – teemu 2012-02-29 06:51:31
我的經驗是MVVM *正確使用*極大地降低了**複雜性。 – 2012-02-29 10:56:00