Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are MVP-Passive View and MVP-Supervising controller

Please describe with a simple example, the differences between MVP-Passive View and MVP-Supervising controller. It would be better to show how data with control is binded and input is validated using both mvp techniques - Passive View and Supervising controller. Thanks

like image 972
Thomas Avatar asked Mar 21 '11 18:03

Thomas


1 Answers

The difference is in view layer updates.

From the Model-View-Presenter pattern page on MSDN:

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. Figure 1 illustrates the logical view of the Passive View and Supervising Controller variants.

The decision to use Passive View or Supervising Controller primarily depends on how testable you want your application to be. If testability is a primary concern in your application, Passive View might be more suitable because you can test all the UI logic by testing the presenter. On the other hand, if you prefer code simplicity over full testability, Supervising Controller might be a better option because, for simple UI changes, you do not have to include code in the presenter that updates the view. When choosing between Passive View and Supervising Controller, consider the following:

  • Both variants allow you to increase the testability of your presentation logic.
  • Passive View usually provides a larger testing surface than Supervising Controller because all the view update logic is placed in the presenter.
  • Supervising Controller typically requires less code than Passive View because the presenter does not perform simple view updates.

Further reading:

Passive View:

http://martinfowler.com/eaaDev/PassiveScreen.html

http://codebetter.com/jeremymiller/2007/05/31/build-your-own-cab-part-4-the-passive-view/

Supervising controller:

http://martinfowler.com/eaaDev/SupervisingPresenter.html

http://codebetter.com/jeremymiller/2007/05/25/build-you-own-cab-part-3-the-supervising-controller-pattern/

like image 95
dantuch Avatar answered Oct 28 '22 12:10

dantuch