Visual Studio can do MVP
Posted February 10, 2008on:
The code beside technology is used by the visual studio designer. E.g. for each Windows Form, visual studio designer generates two partial classes, one for creating UI elements, and the other one is the place to write code. I think it is a MVP/Passive View already.
- Windows Froms App, The SomeForm.designer.cs is the view and the SomeForm.cs is the presenter.
- ASP.NET, the aspx/ascx is the view and the aspx.cs/ascx.cs is the presenter.
- WPF, the xmal is the view and the xmal.cs is the presenter.
If it Visual Studio generates an interface, ISomeForm.cs. Then have SomeForm.cs reference to this interface, instead of being partial class of the view. It is exactly MVP/Passive View. This would make unit testing easy based on ISomeForm.cs and SomeForm.cs. I would not mind if Visual Studio does this (in fact it might be something good to suggest MS to do).
In SCSF and WCSF, there has to be another presenter class. This makes me feel it is a redundant, because presenter class ties/couples to the view. It can hardly be reused. And you have to create extra code to delegate user input/UI events to the presenter. That’s part of reasons why I am not satisfied w/ MVP in SCSF and WCSF.
The original force of MVP is to ease unit testing. Current unit testing on the presenter is to mock interfaces of view and model. Because there is no other better method, this leaves the mocking on interfaces only one to use practically.
What about to have a tool that generates mock object from aspx/ascx to make aspx.cs/ascx.cs unit test-able?