Design Pattern for a Two-State ListView Control?

I have a ListView control in Windows forms that should display a list of items in any icon view or detail view. I would like to separate the ListView state logic and create 2 states of the IconsState and DetailsState classes to remove them from IState, having all the methods that will be called from the user interface window.

In the detailed view, there is the RetrieveVirtualItem event, and in the form of icons, there is the DrawItem event. To call them from the IState variable present in the user interface, both descendant classes must implement them. Having a DrawItem in a DetailsState does not return anything, but returns. Same thing for RetrieveVirtualItem in IconsState.

Is there any other design approach to avoid implementing empty methods in states?

+3
source share
1 answer

Yes, there are better approaches. It’s a designer smell to make a class have a member that shouldn’t be there, that is, in your words: "When using DrawItem in DetailsState nothing happens except return."

In addition, you can use the MVP pattern, which will allow you to significantly increase the degree of verification. With a passive change in MVP, you will have one model, two mute views and a presenter who decides which view to display depending on the user's choice.

MVP:
SO MVP

MVP Windows Forms

0

All Articles