Design template for the "context-sensitive" right-click menu

What is a design pattern that I can use to create context-sensitive right-click menus? I mean the Windows Explorer application, in which the user can right-click on a folder and get a list of menu items, but right-click on a disk and get a completely different list. What design model should I use? Would a factory design template fit for such a menu? Regards, Seb

+3
source share
1 answer

You can check the visitor pattern and builder- and factory -pattern . In pseudo code, you can do something like this:

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

MenuBuilder Builds the appropriate context method based on the object it is visiting.

+4
source

Source: https://habr.com/ru/post/1741824/


All Articles