开发者

Design Pattern for "Context Sensitive" Right Click Menu

What is a design pattern I can use for gene开发者_运维知识库rating "context-sensitive" right click menus ? I have in mind a "Windows Explorer"-like application where a user can right click on a folder and get a list of menu items but right click on a drive and get a totally different list. What design pattern should I use ? Would the factory design pattern be appropiate for handling such a menu ? Regards, Seb


You may want to check out the visitor pattern and the builder- and factory-pattern. In pseudocode you may do something like this:

OnRightClick(Item ClickedItem) {
    ContextMenu = MenuBuilder.Visit( ClickedItem );
    Choice = ContextMenu.Show();
}

The MenuBuilder would construct an appropriate context method based on the item it visits.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜