MVP - Presenter/View

Topics: CAB & Smart Client Software Factory
Nov 28, 2006 at 9:51 AM
originally posted by: imasud

In MVP pattern, Presenter updates the View. A Presenter may observe the model and based on some event it may want to update the View.
How does the presenter get the reference to the view (it is controlling or managing)?
The base controller class only gives the reference to the WorkItem and State.
Dec 2, 2006 at 8:50 AM
originally posted by: ChrisHolmes

"How does the presenter get the reference to the view?"

In CAB, what you'll typically do is provide that reference when the View is created. The presenter will already have a property exposed to get the reference:

public IMyView View
get { return _view; }
set { _view = value; }

Then, when you create the View, allow the Dependency Injection mechanism to create the presenter, and add a line of code to create the reference:

public MyView(CreateNew MyPresenter presenter)

_presenter = presenter;
_presenter.View = this;

Thus, when creating the View, your code looks like:

IMyView view = Items.AddNew<MyView>(SmartPartNames.MyView);

The DI mechanism takes care of creating the Presenter (via the CreateNew attribute) and you provide the linkage with the line of code that reads: _presenter.View = this;
Dec 7, 2006 at 5:52 AM
originally posted by: imasud

Thank you Chirs for such a verbose explanation.
Really Appreciated it.
Imran Masud