What rules do you use to define MVP methods and members

When using the MVP pattern, I often come across methods and members that don't seem pretty in the View or Presenter classes ... My question is, what rules do you use to determine what functions are in the classes? I'm relatively new to MVP, so please humor me.

TIA.

0


a source to share


2 answers


I prefer the passive MVP view option, so this is not a problem for me. In a passive View template, quite a few delegates do something more complex than simply assigning to a presenter.

You end up with a template that looks like this:



public class MyView: IView
{
    private MyPresenter Presenter;

    private OnEvent()
    {
        Presenter.DoSomething();
    }

    public string MyProperty
    {
        get{ return UIControl.Property;}
        set{ UIControl.Property = value}
    }
}

public interface IView
{
    public string MyProperty{ get; set;}
}

public class MyPresenter
{
    private IView view;

    public void DoSomething()
    {
        ...
        view.MyProperty = something;   
    }
}

      

The only tricky part is if you have a datagrid in your form. They take a lot of work to fit into the passive look.

+4


a source


It boils down to how much manipulation of the user interface is. If the method consists of a lot of direct access to individual controls, then it probably belongs to the master. Otherwise, it belongs to the species. The goal is to reduce the interaction between the view and the present to the minimum necessary to complete the software design.

for instance

Presenter.SetListTitle MyList.Name
For I = View.MyListStart to View.MyListEnd
   Presenter.AddListItem MyList(I)
Next I
Presenter.ShowListAddBUtton
Presenter.ShowListDelButton

      



Should be placed in the presenter below

Public Sub UpdateWithList(MyList as AList, View as AView)
  Me.SetListTitle MyList.Name
  For I = View.MyListStart to View.MyListEnd
     Me.AddListItem MyList(I)
  Next I
  Me.ShowListAddBUtton
  Me.ShowListDelButton
End Sub

      

Later, if you decide to change your UI, all you need to worry about is injecting UpdateWithList, not SetListTitle, AddListItem, etc. etc.

+1


a source







All Articles