Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MVP - can a View initialize it's own MVP Triad

Status
Not open for further replies.

JoeAtWork

Programmer
Jul 31, 2005
2,285
CA
I am in a little debate with another programmer about this. The issue is - can a View create it's own MVP (Model View Presenter) triad?

The other programmer thinks this is permissable. He would put the code to initialize the Model and Presenter in the View's constructor, then inject the Model and itself into the Presenter.

My objection to this is that this makes it impossible to use a view with any other model (without changeing the code in the View). Also, it seems to break the very purpose of MVP to have the View using a very specific model.

What say you?

 
Try using dependency injection. And no I don't think the view should do that.

Christiaan Baes
Belgium

My Blog
 
Another reason I have against this is because I can not test a particular View against a mock Model. Since the View would be creating the Model, the only way I can use a mock Model is by modifying code in the View. I don't think I should have to do that, especially if I want to repeat the test in the future.

However, I am not sure if this is a valid argument. It seems that tests would usually be done against a non-visual implementation of the View, i.e. I should just be testing the behaviour against with a mock View.

I can see scenarios though where it would be nice to test the implementation of a view - for example showing a prototype to the customer, or just to evaluate the user-friendliness of a screen, or even just the aesthetics.

I think I've convinced myself that this is a valid argument.

 
You can test views and sometimes you should write tests against the view and not a mock of the view.

If you inject model and presenter in the view via the constructor your IoC-container can easily replace the normal implementation with a mock.

You can use nunitforms and/or white for this.

Christiaan Baes
Belgium

My Blog
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top