Hi there again,
It's been some time and my last question was aimed at the strategy pattern. I wanted to know how I can make use of this pattern to replace a switch/case with something more SOLID. :)
This time, I would like to know about possible best practices in regards to working with an MVP design.
Assume that you have a WinForms project that contains some views that implement interfaces and presenters that connect them to business objects (models) using databinding.
Assume further that you have a view that is able to be presented in different modes. Depending on the mode selected, specific controls in the view are [dis|en]abled, (in)visible, etc...
Usually you'd see something like this:
Presenter:
Switch Mode
Case ModeEnum.Mode1
View.TextBox.Visible = True
View.Label.Visible = True
Case ModeEnum.Mode2
View.TextBox.Visible = False
View.Label.Visible = False
End Switch
I
However... in my case the base code is even more complicated. The answer to the question of what to do with the controls is based on more than one enum, but also some old fashioned strings that contain further selection criterias.
For example:
Switch Mode
Case ModeEnum.Mode1
If Criteria = "Criteria1" Then
View.TextBox.Visible = True
View.Label.Visible = True
Else If Criteria = "Critera2" Then
View.TextBox.Visible = True
View.Label.Visible = False
End If
.
.
.
What I would like to achieve now is implementing a strategy pattern that allows the presenter to call into a context class with the Mode and the Criteria so that the context class can execute a method that manipulates the view accordingly.
Are there any best practices in regards to SOLID?
Other people in my team did something similar. However, they implemented methods within the views that were responsible for manipulating the views' controls and called them from the context class. This however is not OCP. Each time a new mode is added, not only a new strategy needs to be implemented but also a method within the view (you get the point).
So: How do you solve this?
Regards,
Christian.