I've started to wrap my head around the whole MVP pattern and despite I'm doing fine with single objects it starts getting difficult when it comes to collections.
So let's say we're architecting a simple WinForms application that consists of a DataGrid within a Form, with the data Model being a simple collection of stuff, where such stuff has a bunch of properties and the View is going to actually display them:
Model
public class Person
{
public string Name { get; set; }
public DateTime Birth { get; set; }
public bool IsCool { get; set; }
}
public class People
{
public List<Person> Persons { get; set; }
}
View
public interface IPeopleView
{
List<People> ListOfPeople { get; set; }
}
public partial class PeopleViewImpl : Form, IPeopleView
{
private DataGridView _grid = new DataGridView();
public PeopleViewImpl()
{
InitializeComponent();
}
// Implementation of IPeopleView
public List<People> ListOfPeople
{
get { return /* TODO */; }
set { _grid.DataSource = value; }
}
}
Presenter
public class PeoplePresenter
{
private People _model;
private IPeopleView _view;
public PeoplePresenter(People model, IPeopleView view)
{
_model = model;
_view = view;
}
void UpdateView()
{
_view.ListOfPeople = _model.Peoples;
}
}
So what should I implement at View's List<People> ListOfPeople
getter as well as how should I invoke Presenter's UpdateView()
?
And generally, which extra Presenter methods would be interesting to have in order to achieve MVP Passive View and Supervising Controller respectively?
Any advice, code style review or opinion will be sincerely appreciated. Thanks much in advance.