What would be开发者_运维百科 the best way of going about this? I have a method in the presenter that populates various textboxes using a switch statement, but also needs to make sure that only these textboxes are visible, eg.:
switch (operation.CalculationType) {
case CalcType.Type1:
textbox1.Visible = true
_view.TextBox1 = "some value";
break;
case CalcType.Type2:
textbox1.Visible = true;
textbox2.Visible = true;
_view.TextBox1 = "some value";
_view.TextBox2 = "another value";
break;
I'm not fond of the idea of exposing a Visible
property for each control on the form (theoretically this could lead to exposing all sorts of properties, which just seems wrong to me). Another idea I had was to create a method or event that the presenter calls, telling the form to show/hide the controls, but that kind of means replicating the logic in the presenter.
So what's the "proper" way of doing something this?
Thanks
If the variable _view is not an interface you should make it one, implement it and then add a method or methods that setup which textboxes are visible. This way it is clear in the code what you are trying to do and it not tied to that particular form implementation.
Inteface IFormView
Sub DisplayType1
Sub DisplayType2
....
End Interface
精彩评论