2012-09-19 14 views
0

在WinForms應用程序中使用MVP模式我被要求編寫。赦免VB.net,因爲我被迫使用這個:(MVP模式在視圖界面上包含什麼

是新來MVP我已經有一個被動模式的實現,其中有觀點&模型,只有主持人既知道

之間不存在相關性

此視圖的UI哪些功能應該是IVIEW接口

我應該在的iView即

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() 

方法/措施/任務的一部分,使通話查看的表示即在WinForm實現的iView接口

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 

或者我應該保持狀態

Property QItems As IList(Of QItem) 
    Property SelectedQItem As QItem 

    Property QueStatus As QueStatus 

    Property ReportName As String 
    Property ScheduleName As String 

,直接打的電話給演示是在WinForm的一部分,而不是操心利用iView intreface

_presenter.BuildItems() 

_presenter.RunQue() 

你如何權衡何時做EI何時使用MVP?

回答

2

如果您指的是被動視圖方法,那麼您不應該嘗試調用演示者或在視圖內寫入業務邏輯。相反,該視圖應該創建一個主持人傳遞自身引用的實例。登錄表單例如:

public LoginView() // the Form constructor 
{ 
    m_loginPresenter = new LoginPresenter(this); 
} 

public void ShowLoginFailedMessage(string message) 
{ 
    lblLoginResult.Text = message; 
} 

視圖接口應包含允許演示者呈現業務對象的視圖,以及管理UI狀態(間接地)性能。例如:

interface ILoginView 
{ 
    event Action AuthenticateUser; 
    string Username { get; } 
    string Password { get; } 
    string LoginResultMessage { set; } 
} 

的主持人會是這樣的:

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..."; 
} 

很抱歉的C#代碼,但我都沒有碰過VB.NET有一段時間了。

+0

因此,只需使用事件來連接視圖中的功能並讓演示者使用它們即可。 – HoopSnake