aspose file tools*
The moose likes Beginning Java and the fly likes method organization Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "method organization" Watch "method organization" New topic
Author

method organization

Donna Bachner
Ranch Hand

Joined: Oct 08, 2004
Posts: 109
This is a stupid question but when writing a program with many methods is there a special placement of the methods. I have a program with about 10 methods and don't know what order to put them in is there a rule.
Shyam Prasad Murarka
Ranch Hand

Joined: May 02, 2005
Posts: 209
Dear Donna,
I guess that WAS really a stupid question as far as I am concerned. There is no rule or convention for specifying their order. Though I guess its always good to place the main() function either at the beginning of the file or at the end.


With Best Regards,
Shyam Prasad Murarka
Donna Bachner
Ranch Hand

Joined: Oct 08, 2004
Posts: 109
Thanks
Gerardo Tasistro
Ranch Hand

Joined: Feb 08, 2005
Posts: 362
I place them in any order then use Eclipse's outline view to order then alphabetically so they're easier to find. Check your IDE's support for this.
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

Originally posted by Shyam Murarka:
Dear Donna,
I guess that WAS really a stupid question as far as I am concerned.


I don't want to hear you, or anyone else, say anything like this again hear at the Ranch, understand? There are no stupid questions.

There are a number of conventions that people use. I've see public, followed by protected, followed by private; I've seen the opposite, with private first. The convention I tend to use is for each public method to be followed by any private helper methods that it uses.


[Jess in Action][AskingGoodQuestions]
Shyam Prasad Murarka
Ranch Hand

Joined: May 02, 2005
Posts: 209
Dear Sherrif,
I am really sorry for that! Just a slip of the tongue.. I mean fingers.. Will not do it again.
Donna Bachner
Ranch Hand

Joined: Oct 08, 2004
Posts: 109
Hi Guys,
Thanks for letting me know I can put them whatever way I choose. It makes life easier for me.
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

Originally posted by Ernest Friedman-Hill:
... There are a number of conventions that people use. I've see public, followed by protected, followed by private...

Note the reasoning behind this: It allows someone else to look at your code and see all of the public methods -- i.e., those available for outside use (sometimes called the "public interface") -- grouped together up front, so they don't need to look through a lot of supporting code to find something.


"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
Rusty Shackleford
Ranch Hand

Joined: Jan 03, 2006
Posts: 490
Originally posted by Donna Bachner:
Hi Guys,
Thanks for letting me know I can put them whatever way I choose. It makes life easier for me.


Yes, you can do it however you choose. Like others have said, there are lots of ways to do it. Just make sure it is in some logical order of your choosing. If each class you write is organized randomly, it will make life harder.


"Computer science is no more about computers than astronomy is about telescopes" - Edsger Dijkstra
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: method organization