I whipped up a demo on Friday before the holiday weekend of using the Model-View-Presenter pattern (the "Passive View" version, I believe) that I want to show to my co-workers this week as an example of how to architect our WebForms application moving forward and get maintainable, clean code. We currently keep almost all logic outside of some data access routines in the code-behind files.
I know immediately one of the points raised will be that it's faster/easier to just use code-behind rather than create a separate class library for the views and presenters, and having to create a separate view per page (that at least can get hairy as we have well over a hundred pages, although at this point I'm talking about future development and not retrofitting the rest of the code). The argument will be that it's much faster to get a task done by doing something like this:
protected void Page_Load(object sender, EventArgs e)
{
DataSet ds = Customer.Get(Request.QueryString["custid"]);
if (ds.Tables[0].Rows.Count > 0)
{
txtFirstName.Text = ds.Tables[0].Rows[0]["fname"].ToString();
// other properties here..
}
}
than this:
// CustomerDetails.aspx
private CustomerDetailsPresenter _presenter;
protected void Page_Load(object sender, EventArgs e)
{
long customerId = Convert.ToInt64(Request.QueryString["custid"]);
_presenter = new CustomerDetailsPresenter(this);
_presenter.Init(customerId);
}
// CustomerDetailsPresenter.cs
class CustomerDetailsPresenter
{
private ICustomerDetailsView _view;
// ctor here...
public void Init(long customerId);
{
// get customer somehow, via ORM or DataSet or whatever...
_view.FirstName = firstName; // some string, whether from dataset or ORM
}
}
What counter-arguments can I use to show the benefit of using the MVP pattern? Specifically ways it would improve the speed and efficiency of getting things done. Just saying "it's cleaner" or "you can properly abstract the code" isn't enough because code quality has never been a big issue, just speed (and now that mentality is biting us in the rear).
NOTE: This is for new features to an existing brownfield/legacy application, not for a new site (I would chose MVC for a brand new site). New pages that have to interact with the application as a whole, radical changes to old pages, and the like is what we normally do and what I'm talking about using MVP for.
I need some counter-points to counter the argument of why NOT to use M-V-P
. Then in the text you sayWhat counter-arguments can I use to show the benefit of using the MVP pattern?
Technically it may be correct, but isn't it a bit confusing?