Dofactory.com
Dofactory.com
 Back to list
Views:   2K
Replies:  1
Archived

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,
E-John


E-John Lien, May 07, 2018
, This is a great article. It gave me a lot of useful information. thank you very much.
May 15, 2018
Reply 1
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:
https://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93presenter
Robert Bajomi Christensen, May 11, 2018
Stay Inspired!
Join other developers and designers who have already signed up for our mailing list.
Terms     Privacy     Cookies       Do Not Sell       Licensing      
Made with    in Austin, Texas.  - vsn 44.0.0
© Data & Object Factory, LLC.