0
我有一些代码在模型中包含了一些类,如(vb.net伪代码,但可以是任何面向对象的语言):避免子类型选择
Enum AttributeType
Boolean
Date
String
End Enum
MustInherit Class Attibute
Must Override Function Type As AttributeType
End Class
Class BooleanAttribute: Attribute
Function Type As AttributeType
Return AttributeType.Boolean
End Function
End Class
而且视图包含像一些代码:
Select Case AttributeType
Case Boolean
//Display checkbox control
Case Date
//Display date picker control
Case String
//Display textbox control
End Select
我真的不喜欢在视图中的代码,对希望显而易见的原因 (当我得到一个新的属性类型等发生了什么)。我的问题是,我应该如何替换 呢?
我可以很容易地添加一个方法到具体的类,但是用UI的东西污染 模型,所以这是一个可怕的想法。
我可以将选择移入工厂,但似乎只是隐藏了 问题。
任何人都可以建议一个更好的方法吗?