• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

method organization

 
Donna Bachner
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 209
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Donna Bachner
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks
 
Gerardo Tasistro
Ranch Hand
Posts: 362
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 24211
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Shyam Prasad Murarka
Ranch Hand
Posts: 209
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Guys,
Thanks for letting me know I can put them whatever way I choose. It makes life easier for me.
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Rusty Shackleford
Ranch Hand
Posts: 490
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic