演示者在视图上显示复合对象

时间:2014-06-25 12:55:08

标签: c# .net winforms mvp composition

我有一个MVP三元组WageInfo模型,WageView视图和WagePresenter演示者。 WageInfo具有名为List<Earning> EarningListList<Deduction> DeductionListList<WageBalance> WageBalanceList的复合对象列表。

我的演示者希望在视图中的三个单独DataGridViews中显示收入,扣减和工资平衡。因此,演示者询问WageInfo,然后WageInfoDataService获取数据并创建所有三个列表,并且它将返回包含所有对象列表的WageInfo实例。演示者然后演示者选择在视图上显示的内容如下。

class WagePresenter
{
    var wageInfo = WageInfo.GetEarnings(); // return a WageInfo instance
    _View.Earnings = wageInfo.EarningList; // choose EarningList to show on the view
}


class WageInfo
{
    public List<Earning> EarningList; // composition of EarningList in WageInfo
    // Other lists



    public WageInfo()
    {
        EarningList = new List<Earning>();
        // Instantiate other lists



    }

    public WageInfo GetEarnings()
    {
        this.EarningList = CreateEarningList();
        return this; // return current instance of WageInfo
    }

    private List<Earning> CreateEarningList()
    {
        var dataTable = _DataService.GenerateEarnings(); // DataService returns a DataTable
        return ConvertDataTableToList(dataTable); 

    }

    private List<Earning> ConvertDataTableToList(DataTable dt)
    {
        //Use data in the dt to create a list of Earning objects
        return list;
    }
}

我只是想通过声明EarningList等公开来了解我是否打破了这里的构图?

如果我声明EarningList私有,那么我可以在WageInfo中使用公共方法返回EarningList。这比宣布EarningList公众更好吗?

如果两个选项都不正常,那么我的演示者如何在单独的DataGridViews中显示每个列表?

编辑:课程收入如下......

class Earning
{
    public EmployeeID {get; set;}
    public BasicSalary {get; set;}
    public OverTime {get; set;}
    public Allowance {get; set;}
}

0 个答案:

没有答案