MVP, WinForms - how to avoid bloated submission, presentation and presentation

When implementing the MVP pattern in winforms, I often find bloated view interfaces with too many properties, setters and getters. A simple example would be a view with 3 buttons and 7 text fields, all of which have values, allowed, and visible properties displayed in the view. Adding test results for this, and you can easily get an interface with 40ish properties. Using a view model, there will be a model with the same number of properties.

How do you easily synchronize presentation and presentation model without bloated presenter logic that passes all values ​​back and forth? (With this 80ish presentation encoder, imagine a test presenter mocking a model and presentation would look like this: 1.60ish lines of code to just simulate this transmission.) Is there any infrastructure to handle this without resorting to winforms data binding? (you can use different views than winforms view. According to some, this synchronization should be the task of the speakers ..) Could you use AutoMapper?

I may be asking the wrong questions, but it seems to me that MVP is easily bloated without any good solution here.

+4
source share
1 answer

This is just one idea, and I know that some people may not like it - here you can do a lot.

If you find that you use a lot of template code, encapsulate it.

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

In your opinion, 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 complete the various properties associated with each field.

By the way, I suggest you not to clutter up these interfaces manually for testing - use a mocking structure.

+3
source

Source: https://habr.com/ru/post/1311415/


All Articles