Subscribepublic class MainClass {
public static void main(String args[]) {
MainInitializer::Initialize();
DoTheMainJob();
}
}
class MainInitializer {
static void Initialize() {
static bool isInitialized = false;
if (isInitialized) {
throw("WTF?");
}
InitializeSomeCrap();
InitializeSomeOtherCrap();
InitializeMoreCrap();
}
private static void InitializeSomeCrap() {
InitializeSomeCrapStep1();
InitializeSomeCrapStep2();
}
// et cetera
}You have classes for various robot behaviors: Walk, Sit, Grab, etc. But let's say it just so happen that grabbing is really complicated. It takes 3000 lines of code to grab, but those lines are always run in the same order.Why not?
You don't want as 3000 line-long class!
Scrolling up and down in a huge file would be a nightmareYou need a better IDE, not a design pattern.
And there ARE logical ways to group the init methods. There are batches of them that init the same thing and other batches that group other things.Which is why I made my example group things. Initialize() called three different functions: InitializeSomeCrap(), InitializeSomeOtherCrap(), InitializeMoreCrap().
Here's a better way of stating my problem: imagine you have a thousand initialization steps, and each step takes two-to-fifty statements. How would you organize those steps?If they can be logically grouped together, then do so. That's what I was attempting to show you in that portion of my example.
One way would be:
function step1() { /* etc. */ }
function step2() { /* etc. */ }
function step3() { /* etc. */ }
function step4() { /* etc. */ }
...
function step1000() { /* etc. */ }
But it seems to be like there should be at least one higher level of organization, especially since steps 1 though 10 could be logically grouped together (e.g. data parsing), as could steps 11 through 25 and so on.
You are not logged in, either login or create an account to post comments
posted by grouse at 10:28 AM on April 16