tags:

views:

195

answers:

1

I have a object that is responsible for controlling screen navigation. A presenter can call one of two methods on this navigator object NavigateTo(string screenName) and NavigateTo(string screenName, object data). This latter method allows some context data to be passed to the navigator object.

Would it be the wrong approach when calling the NavigateTo(string screenName, object data) to pass the calling presenter as the data to the navigator and then allow the navigator object to use this to extract data from the view and/or model.

Some advice on this matter would be greatly appreciated.

A: 

Passing the Presenter to NavigateTo is a good choice. If you have multiple presenters you may want to write a interface that NavigateTo can use and have each presenter implement that interface. But if you just using one presenter for this or they already share some common interface then this is not needed.

One idea behind MVP is that you are change the view without effecting the underlying UI Logic. Passing the presenter doesn't effect this goal of MVP as you can change the view the Presenter is using. Now if you are allowing direct access to the raw view through the presenter (by exposing a view property) then that not good. What you want are methods on the presenter to expose the needed information to NavigateTo. That way when you chance the view you re implement the code behind those methods.

RS Conley
Thanks for comments. You say allowing direct access is not good. But what if I am using the view interface to access properties of the view? Is this still considered inappropriate?
David
no, what if you changed the view? There is nothing to indicate what part of the view is being used by other part of the software. So 5, 10 years from now you change it and then your software breaks. The view should only be directly referenced by the presenter.
RS Conley
Thanks once again. I assume this is the rule that an object should only collaborate with its neighbour.
David