File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Cattle Drive and the fly likes Where to split methods (Say 4b) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » This Site » Cattle Drive
Bookmark "Where to split methods (Say 4b)" Watch "Where to split methods (Say 4b)" New topic

Where to split methods (Say 4b)

Dean Funk
Ranch Hand

Joined: Apr 20, 2001
Posts: 42
Lessee if I can get my point across without a spoiler...
I'm trying to decide where to split up a process into methods.
I have a Long.
I want to split it into three-digit chunks, then further process the chunks.
Does it make more sense to split up the Long in main(), then pass the chunks to a processor method,
or to pass the Long to some method, split it up, process it in that method or pass the chunks to some tertiary method?
I can argue it to myself each way, please somebody weigh in.
jason adam
Chicken Farmer ()
Ranch Hand

Joined: May 08, 2001
Posts: 1932
I would separate processes into methods. Personally, I put processing in main only when it's some simple output or very basic logic needed (ie testing to make sure an input is within the scope of the program). Otherwise, I group related processes in a method and return values or call other methods as needed. Figure out what processes you are going to need, divide those into logical groupings, and design your methods around those.
Just to give you an idea, I had a total of 4 methods in my 4b code.
Hope this helps,
[This message has been edited by jason adam (edited August 08, 2001).]
Amber Woods
Ranch Hand

Joined: Mar 28, 2001
Posts: 111
I sent the long to a method to be processed. Like Jason, I also ended up with 4 methods besides main to do all of the processing. Take Jason's advice on this he seems to be a wiz when it comes to the Assignments
Best of Luck to you Dean
[This message has been edited by Amber Woods (edited August 08, 2001).]

"Happiness is a way to Travel, <b>Not</b> a Destination" -- Unknown
Dean Funk
Ranch Hand

Joined: Apr 20, 2001
Posts: 42
What made y'all decide on passing a Long?
I was starting to gravitate toward handling the thing as a String, because it doesn't stay Long very long.
Greg Harris
Ranch Hand

Joined: Apr 12, 2001
Posts: 1012
i ended up with 5 methods. i converted the string to a long in the first method and dealt with the math from then on using other containers for each segment... my long did not stay long after the first method.

jason adam
Chicken Farmer ()
Ranch Hand

Joined: May 08, 2001
Posts: 1932
I dealt with a number instead of a String through most of the program just because that is the way I think. If we're talking about numbers, it was easier for me to write code that dealt with the number pattern versus how to break apart the String, but it can be done relatively similar either way. I guess it all depends on how you view things.
I actually had 3 extra methods, and then main(). main() just checked the range of the input, and then sent the number on for processing. I'd probably be giving away too much if I even hinted at what the others did
Dean Funk
Ranch Hand

Joined: Apr 20, 2001
Posts: 42
Awww c'mon...
Thanks, everybody.
Terence Doyle
Ranch Hand

Joined: May 30, 2001
Posts: 328
I do a little processing in the main() which I supppose could be an excuse for a separate method - though personally I think its OK.
The rest then is done by just one method...
Course I haven't been nitpicked yet...
I'm sure I'll be posting back with a different structure once I get on to sending it in.


Raising Flares debut album 'Ignition' out now

Terry Doyle <br />SCPJ 1.4 , SCWCD , SCMAD(Beta)
Adam Vinueza
Ranch Hand

Joined: Apr 16, 2001
Posts: 76
Hi Dean,
For what it's worth, here's my own 2 cents.
The rough guide I've been using is that if I'm repeating code more than I need to, I use a separate method; otherwise, I use main(). Since I'd break the argument into three-digit chunks only once, and doing it is not essential to some other procedure demanding a separate method, I'd favor doing it in main().
As for String vs. long: I don't see any special advantage to using String, because it seems to me that, in the case of Say, to break a String up into three-digit chunks is more trouble than it's worth. Say has to be able to either add chars to the front of the String to make it divisible by 3 w/o remainder, or take a less-than-three-digit chunk. Also, the chunks have to be converted to ints separately. None of this is necessary if long is used instead of String.
I agree. Here's the link:
subject: Where to split methods (Say 4b)
Similar Threads
Recipe for disaster, or, Java noob writing a pattern recognition program
Few Large Classes/Methods vs. Many Small Classes/Methods
SwingWorker and Communications with GUI
Notifying user using JSF after the Asynchronous session bean method completes
Function Point Analysis