what classes would you make for a menu structure?

Posted by joey eisma on 28-Jul-2016 15:39

hi,

what classes would you create for a menu system, when you have menubar, which has sub menu or menu item, and sub menu has sub menu as well.

what of relationships would you have? (aggregation, composition, inheritance)


TIA!

All Replies

Posted by Matt Baker on 03-Aug-2016 15:11

Since you're dealing with UI, think "MVC".

To start with something simple, you'll need 3 (possibly 4, if you want to go MVVC).

Start with your Model (MenuItem class) It has a label, an icon, a unique id, and an optional set of children MenuItems. Maybe some other properties for things like toggle state, and what not.  

Then you need a View (MenuViewer) class to interact with your rendering technology (.NET, ABL, HTML...).

Then you need controller (MenuController) class.  This handles activation state, event callbacks and what-not.

Then you can add in other features like fill-ins and combo boxes, as search fields in your toolbar.

You can then go a step further and split the active menu items (e.g. what is supposed to be on the screen), vs the "what are the full set of possibilities".  This full set of possibilities gets stripped down based on user preferences, security options, and active context (i.e. what is currently selected in your UI).

Take a look at someone else's (Eclipse), to gather some ideas.

wiki.eclipse.org/Menu_Contributions

and

www.vogella.com/.../article.html

This thread is closed