Question

I am still trying to get my brain wrapped around MVP. What should I use the controller class for? Is that where I access data resources?

Was it helpful?

Solution

The Controller should act upon a Model, perhaps populating a model via a service layer call to a database. Usually with requests from the view the controller performs actions on the model.

The View is the presentation onscreen.

The Presenter handles flow between view and controller.

The reason for separating out presenters and controllers might be so that you can reuuse a certain controller with a different presenter etc.

OTHER TIPS

In my opinion the presenter should not be coupled with the UI technology and should directly deal with the services layer of the model. There should just be a single controller in the application and that could be tightly coupled with the UI technology. Page navigation could be abstracted in the controller. I feel that, WCSF based MVP-Controller pattern is a slight variation of the original MVP pattern.

Let me suggest that presenter are to be implemented for reuse while controllers are not.

The controller in MS's WCSF examples hold data shared by multiple presenters in the module, expose methods to act upon that shared data, and manage the shared data in the web session. For instance, a list of money transfers objects used by a NewTransfer presenter and a TransferHistory presenter.

Data that is unique to 1 presenter only could be accessed through the controller, but doesn't need to be. The presenter could manage the data access and web session data itself in this case.

That's my interpretation after looking at a few examples over a couple of years, e.g.

I'm not sure whose definition of "controller" they're using, but it's not the same as the one in MVC.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top