Saturday, January 15, 2011

Passive view

Passive view is an approach of the Model-View-Presenter (MVP) pattern. In Passive View the view is devised as thin and passive as possible.

In a Passive View approach, the view is a raw sequence of UI elements with no additional data binding or formatting. The presenter acts directly on the UI elements and works simply by loading data into them.

Advantages:
  • You have an inherently more testable system because the logic in the view is reduced to an absolute minimum.
  • You run no risk at all by not testing the view.
  • The Passive View is very explicit mechanism. This makes is much easer to read the code see what is happening - particularly useful if you're trying to debug when things go wrong.
  • It easy to support multiple GUIs. The presenter ignores any UI technology behind the view.
Disadvantages:
  • A really passive view can be quite cumbersome to write  and maintain and can add a lot of complexity to the presenter. 

See also this post in Martin Fowler's website to get more details.

The core of the MVP is interaction between the view and the presenter, why I don't declared any interface or class for the model.

Here is my implementation of Passive View:

IView.cs
using System;

namespace NOrca
{
 public interface IView : IDisposable
 {
  IPresenter Presenter { get; set; }
  event EventHandler<ActionEventArgs> Action;
  void RaiseAction(object sender, string actionName, params object[] arguments); 
 }
}

IPresenter.cs
using System;

namespace NOrca
{
 public interface IPresenter : IDisposable
 {
  IView View { get; set; }
  void Initialize();
 }
}

No comments:

Post a Comment