I totally understand the MVP pattern now, but I still struggle to see where views and presenters are instantiated. I have seen some examples where the presenter is newed up in the view, but is this correct. After reading a blog post of Jeremy Miller about communicating between View and Presenter he had a function on the Presenter to attach the presenter to the view.
My question is then this: Where should views and presenters be created? Also where in winforms and webforms.
In Winforms, I instantiate the view as required (eg: in the main
method, or in a method on another presenter, but wherever makes sense really). The view then creates and registers itself with a new instance of a presenter.
This makes having several views use the same presenter logic easy, and shields users of my view from my particular architectural decision to use MVP.
In webforms, the page gets instantiated by the request. Since the page is the view and you cannot control the order of execution, it is the view that has to register itself with the presenter
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With