Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to build a command line interface with menus and sub-menus and eventually the leafs of the tree should be operations like.. bank management -> account management -> add acount (insert account info) And I'm looking for a good way which works with the OO principles...

Thanks for any piece of advice!

share|improve this question
navigating a CLI can be seen as traversing a state machine, with each state a menu and the edges the commands at each menu – ratchet freak Mar 27 '13 at 10:38
yeah..but should do it with a while loop? or stuck with it – user1050389 Mar 27 '13 at 11:10
I tried making a "menunude" abstract class which has the sub classes menu and has a list of menus and operation has an execute function which does whatever it's supposed to do...the problem is what to put in the main thingy – user1050389 Mar 27 '13 at 11:27
up vote 1 down vote accepted

if you want OO I suggest a Menu interface with methods to write out the options and parsing the input and returning the next Menu

so your main loop becomes:

Menu menu = new StartMenu();
    Menu res = menu.parseInput(stdIn.readline());
share|improve this answer
Thank you, that's exactly what I've been looking for!! – user1050389 Mar 27 '13 at 11:30
But what If I want to encapsulate the whole loop inside a seperate menu class,How should I do that? – user1050389 Mar 27 '13 at 11:58
You could put this code inside a static method in the base class if you really wanted to. Call it RunMenu(). – Ben313 Mar 27 '13 at 16:33

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.