As always: I am no expert, so I'll just give you my take on the issue...
The short answer is "yeah, kind of". There is no clear cut rule, and that if it makes sense to pass information from method to method 32 methods away from main(), then that is what you will end up doing.
Usually, though, I find that main() is a starting point, and if I am working with objects, main() is a good place to instantiate the object that is in charge of directing traffic in my program. Who does what next seems to be more of a question of who can take responsibility for what. When I make a class, I am always asking myself "what does this object know, and what can this object do?".
In a school administration program, students know who they are, what classes they are taking, and they can apply for classes and take exams. They can check information about classes they are enrolled in (who is the main lecturer? When is the midterm?). A student should not be able to write their own diploma, though - the writeDiploma() method belongs in a different object... not Student, not Professor, probably some form of Administration object.
In the beginning of the cattle drive, there is no need for objects, and main() often holds the control structure of whatever you are doing, but you can make methods to get specific things done, and sometimes you will make a method that does a rather large specific thing, and want to have small methods that can take care of something that you need to do in the larger method.
Hm... it seems like you can sum up all of the above to say: It depends.
Try stuff out, play around with it. The more you try different ways of doing things, the more the nitpickers will be able to guide you in the right direction.
- my two cents
Joined: Jan 30, 2007
Thank you Katrina and Marilyn for your responses. I don't program for a living so little things like this sometimes puzzle me. I did take a class in VB.Net at a local college and was taught to start the program from main and terminate the program from main. Any pre-application initialization and post application administration can be put in main as well.
Marilyn de Queiroz
Joined: Jul 22, 2000
Java kind of does that for you automatically behind the scenes, Mark. Even if you don't return anything, the method returns up the chain of methods and ends up back in main. But that's not obvious because you don't see anything happening. To see this, put a System.out.println call just before the closing curly brace in main and watch when it prints -- just before the program exits -- regardless of whatever else prints while the program is running. At least that's true in the little applications we're writing in the CattleDrive.
But ... it's not something you have to do. It may appear to you that the program ended somewhere else, and that's fine too. [ February 25, 2007: Message edited by: Marilyn de Queiroz ]