开发者

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

开发者 https://www.devze.com 2022-12-22 03:15 出处:网络
I have a menu click event that looks something like this.... Public Sub ToolbarManager_ToolClick(sender as Object, e as EventArgs)

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

精彩评论

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

关注公众号