views:

67

answers:

2

hi,

When I have a button which only changes something in my view (e.g. such that some text appears if I press it), can I write its whole code in the file with my view or should I include event handling of this button in the presenter? This is problem for me, because I don't know, if the presenter handles all events from the view or only these, which change something in the model?

Thanks in advance

A: 

I think that it depends on how you feel comfortable. Personally, I prefer the Passive View implementation but, if I got it right, both Passive View and Supervising Controller prescribe that the View should be updated by the Presenter (apart from simple data-binding in the case of Supervising Controller). Another exception could be if your view is a web form and you want to update it client side via javascript.

You could have a look at the following:

http://msdn.microsoft.com/en-us/library/ff647543.aspx

where you can find the paragraph: View Updates

"When the model is updated, the view also has to be updated to reflect the changes. View updates can be handled in several ways. The Model-View-Presenter variants, Passive View and Supervising Controller, specify different approaches to implementing view updates.

In Passive View, the presenter updates the view to reflect changes in the model. The interaction with the model is handled exclusively by the presenter; the view is not aware of changes in the model.

In Supervising Controller, the view interacts directly with the model to perform simple data-binding that can be defined declaratively, without presenter intervention. The presenter updates the model; it manipulates the state of the view only in cases where complex UI logic that cannot be specified declaratively is required. Examples of complex UI logic might include changing the color of a control or dynamically hiding/showing controls."

Hope it is helpful

Matteo

ilmatte
A: 

Presenter only handles the events which change the model. However, each programmer decides himself on what should be put to model, and what belongs entirely to the view.

Imagine the task, where you need to make 2 buttons. First button loads data from database and shows it, and second button changes the color of the page to some random value. There are 2 ways to implement it:

  1. Model will have LoadedData loadedData and Color color. Presenter would manage both buttons that way.
  2. It could be decided that color is part of the presentation part, and has nothing to do with the model. This way - there would be no color in the model, and all the random color generation and button even handling would appear in the view.

So, to sum it all up, if you want/need/decide on to put that text into the model - presenter can and should manage that button. But if that text is independent from the main logic and is part of the presentation (some design element) - it should not be put into the model and should not be managed by presenter.

Max