开发者

Recommend an Appropriate Object-Orientated Design Pattern To Replace This Code

I have a menu click event that looks something like this....

Public Sub ToolbarManager_ToolClick(sender as Object, e as EventArgs)
    Case "New开发者_高级运维"
        CreateNewFile()
    Case "Save"
        SaveCurrentFile()
    Case "Exit"
        ExitApp()
    Case.......
    etc...
    etc...
End Sub

This strikes me as being 'ugly' - but I'm unsure of the 'best' way or the most appropriate way to clean it up.


Command design pattern


If the switch case is just in one place, I'd bite my lip and live with it.

If it's mushrooming everywhere, I'd try to use Replace conditional with polymorphism

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜