Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where should View & Presenter be born

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.

like image 438
adriaanp Avatar asked Dec 09 '08 22:12

adriaanp


2 Answers

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.

like image 24
Dan Vinton Avatar answered Oct 21 '22 07:10

Dan Vinton


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

like image 64
Matt Briggs Avatar answered Oct 21 '22 07:10

Matt Briggs