Steve Chambers Steve Chambers - 1 month ago 13
Java Question

Should a worker method generally be placed above or below the methods that call it?

Are there any conventions as to whether a method called by another method should generally be above or below it? E.g. say

caller()
was refactored into two methods - where would be the more standard place out of
aboveCaller()
or
belowCaller()
?

private void aboveCaller() { /*...here?...*/ }

public void caller() {
aboveCaller();
belowCaller();
}

private void belowCaller() { /*...or here?...*/ }


Although this is in Java, it is a general programming question and not really aimed at a specific language. (Apologies if it has been asked before - tried searching on here but didn't come up with anything).

Answer

Following the top-down design, I first write the methods calls, then implement them, so they'll be under.

Others prefer them to be above the caller since it's clearer (You first encounter the implementation, then see the call).

One thing for sure, follow your convention.