Question

When implementing MVP pattern in winforms I often find bloated view interfaces with too many properties, setters and getters. An easy example with be a view with 3 buttons and 7 textboxes, all having value, enabled and visible properties exposed from the view. Adding validation results for this, and you could easily end up with an interface with 40ish properties. Using the Presentation Model, there'll be a model with the same number of properties aswell.

How do you easily sync the view and the presentation model without having bloated presenter logic that pass all the values back and forth? (With that 80ish line presenter code, imagine with the presenter test that mocks the model and view will look like..160ish lines of code just to mock that transfer.) Is there any framework to handle this without resorting to winforms databinding? (you might want to use different views than a winforms view. According to some, this sync should be the presenters job..) Would you use AutoMapper?

Maybe im asking the wrong questions, but it seems to me MVP easily gets bloated without some good solution here..

No correct solution

OTHER TIPS

This is just one idea, and I know where some people might not like it -- there are lots of different things you can do here.

If you find yourself using a lot of boilerplate code, encapsulate it.

public class UiField<ContentType>
{
    public bool IsEnabled { get; set; }
    public ContentType Value { get; set; }
    public bool IsVisible { get; set; }
}

In your view, then:

public interface ISampleView
{
    UiField<bool> IsStaffFullTime { get; set; }
    UiField<string> StaffName { get; set; }
    UiField<string> JobTitle { get; set; }
    UiField<int> StaffAge { get; set; }
    UiField<IList<string>> Certifications { get; set; }
}

Here you wrap up the various properties associated with each field.

Incidentally, I suggest that you not stub these interfaces by hand for testing -- use a mocking framework.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top