Home  /  Questions  /  Question

0   0
16 days ago

Why do we pass the "this" reference to View of Presenter from FormLogin?

Dear SIR,

I am E-John, a novice of Design Pattern.
I am tracing the Patterns In Action 4.5 WinForms
Some simple questions can not understand,

When "Login" button is pressed, a FormLogin in is created and a LoginPresenter is created.

_loginPresenter = new LoginPresenter(this);

LoginPresenter is inheritanced from Presenter, 

LoginPresenter (subclass) -> Presenter (base class) 

here the "this" reference is passed to LoginPresenter,
the "this" reference is FormLogin instance here, 
Finally the this reference is passed to Presenter(T view)
and view = this is passed to field of Presenter View,

1. Why do we pass the "this" reference to View of Presenter from FormLogin?
2. The parameter of Presenter(T view), T is generic type
    The parameter of LoginPresenter is ILoginView, because LoginPresenter : Presenter<ILoginView>
    "this" is reference of FormLogin instance,
    How is the relations of casting?

Thanks and Best regards,

 1 comment
, This is a great article. It gave me a lot of useful information. thank you very much. --- Chuoiit43 Chuoiit43  8 days ago

13 days ago
Hi E-John,
The "this" is the actual "View" implementation, which you call your instantiation from, as you use M-V-P pattern.
See the generic description of the pattern here: