personally I would always try to keep main rather clean. Depending on the complexity of your program and the likelyhood of extending upon it of course, a couple of lines of code just to learn something never hurts.
From the info you give I would probably create a menu processing object or something like that and store the methods for displaying and the menu choices and processing them in there. That allows for a lot of flexibility in your desing and keeps main easy to understand (if you choose meaningful object and method names of course).
Hope I have given you some ideas to work with.
If the use of certain language constructs that get the job done is still considered OOP is something I like to leave to the academics, it's usually easier to debate politics or religion then OOP software design with some people.
Timothy had a good question about making another static method for each choice in the menu. I try to get out of static mode right away by creating a real object instance:
This makes someMethod() more like most of the non-static methods on most objects.
Now you can create a method per case. In "real life" I'd start to get concerned after about 5 choices, but for practice or school assignments I wouldn't worry too much if there are more. There are there are a couple rather advanced ways to replace a long case statement with other structures. Something to look forward to later.
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Joined: May 25, 2005
so I should do this??
Should I put option1() & option2() as static function??? if i do it in the above way, will it still be object oriented??
Joined: Jan 29, 2003
Yes, that puts the code for each option cleanly into its own method. This isn't gospel or anything, but instance methods are somewhat "better object stuff" than static methods. One exception might be if we moved the methods to an object (instead of the class) and then only ever made one instance of the object, which is probably just what you'd do, so it's a bit of a toss-up. I'd probably go to something like this:
Now I can write and test getUserChoice with no other methods. I can write and test doSomeAction without the menu. That's not much change from what you had, but tries to make each method say exactly what it does in the fewest possible words. Sound like fun? [ August 28, 2005: Message edited by: Stan James ]