Reputation: 736
Using a MVP Pattern in a WinForms app I have been asked to write. Pardon VB.net as I am being forced to use this :(
Being New to MVP I have gone with a Passive Model implementation where there is no dependency between the View & the Model and only the Presenter knows both
The View being a representation of the UI what functionality should be part of the IVIEW interface
Should I have the methods/actions/tasks in the IView i.e
Property QItems As IList(Of QItem)
Property SelectedQItem As QItem
Property QueStatus As QueStatus
Property ReportName As String
Property ScheduleName As String
Sub BuildQItems()
Sub RunQue()
Sub StopQue()
Sub CancelCurrent()
Sub PauseCurrent()
and make the calls view the Iview Interface that is implemented in the winform
class Winform
implements IView
Private Sub btnCreate_Click(sender As System.Object, e As System.EventArgs) Handles btnCreate.Click Implements IVIEW.Create
If (_presenter.CreateSchdule()) Then
MessageBox.Show("Sucessfully Created")
Close()
End If
End Sub
End Class
or Should I just hold the state
Property QItems As IList(Of QItem)
Property SelectedQItem As QItem
Property QueStatus As QueStatus
Property ReportName As String
Property ScheduleName As String
And make the calls directly to the Presenter which is part of the WinForm and not bother about the Iview intreface
i.e
_presenter.BuildItems()
_presenter.RunQue()
How do you weigh up when to do either approach when using MVP ?
Upvotes: 0
Views: 2286
Reputation: 747
If you are referring to the passive view approach then you should not try to call the presenter or to write business logic inside the view. Instead, the view should create an instance of the presenter passing a reference of itself. Login form example:
public LoginView() // the Form constructor
{
m_loginPresenter = new LoginPresenter(this);
}
public void ShowLoginFailedMessage(string message)
{
lblLoginResult.Text = message;
}
The View interface should contain properties that allow the presenter to present business objects to the view as well as to manage the UI state (indirectly). Ex:
interface ILoginView
{
event Action AuthenticateUser;
string Username { get; }
string Password { get; }
string LoginResultMessage { set; }
}
The presenter would be something like:
public LoginPresenter(ILoginView view)
{
m_view = view;
m_view.AuthenticateUser += new Action(AuthenticateUser);
}
private void AuthenticateUser()
{
string username = m_view.Username;
...
m_view.ShowLoginResultMessage = "Login failed...";
}
Sorry about the C# code but I haven't touched VB.NET for a while now.
Upvotes: 2