How to go about display multiple "Menu" classes in java -


Hi all I'm relatively new to OOD and Java so I'm not sure how to do this properly.

Currently, I need to create an application (based on the console / command prompt), which says that it has to go through a series of "menus" where the application will show your choice and you will have 1/2 / 3/4 etc. My professor told me to break my boundary class (class where all of the options are included) because it is too long (400 + lines).

Now the problem is that if I was about to break it, then I would have to maintain a new object class to call different menus in different classes. For example:

Let's say that my main menu, food menu, dreammanu. So my main method would be to call displayMenu () to make the main menu object. From there, if I want to navigate in the food menu, I will have to create another food menu item and call the menu again under it. Apart from code, if I want to navigate back to the main menu, then I will have to recreate the main menu item and call it on the display menu.

In the above method there are so many variables to collect garbage and total waste of memory. Is there another solution around this? Thank you very much in advance.

Hamilin

Extend all your menus one (okay) or one ( Better), if you are not doing this already.

How to access the menu, you can store each menu in a menu array or some other archive (for example, a map if you have a string or other Want to be able to use the object). That collection is made globally accessible (in stable some public class) and then you can display the same frequency of each menu.

Comments