God Method

A "God Method" is a method that does way too many processes in the system and has grown beyond all logic to become The Method That Does Everything.


Lisp/Scheme Objects, implemented as closures, might qualify as a GodMethod. Similarly, Records may qualify as GodMethods in untyped curried languages where a projection on a record is equivalent to passing a parameter to a function.

And that doesn't even touch on LambdaTheUltimate systems where everything is a function... and the GodMethod is omnipresent, albeit not omniscient.


An example of the typical GodMethod that appears, specially in data oriented aplications is (in Java):

 public Object execute(Object objects)

or for those that believe in the all powerful string:

 public Object execute(String objects)

or even (but not much better):

 public ResultSet execute(String objects)

The interesting thing, is that, as need for new processes increases suddenly some programmers realize.. why should I create a new method for each processe if can only add an "if"... I think this is because this kind of programmer has FearOfAddingMethods. Another interesting phenomena is that if the process can be specified in some kind of languange then it is almost a sure thing that a GodMethod will appear:

 public Result execute(RelationaAlgebraExpresion? expression)

The thing is that any sufficently complex object graph can represent a kind of language of a domain so there seems to be a fight (or complicity?) between objects graphs and GodMethods?...

In Java, I've also seen the related GodConstructor?, especially for making Swing objects. Each Component subclass does all the setup of itself and layout of its children within a honking huge constructor. The object then just hangs out in the component hierarchy, delegating events to anonymous event handler objects that were also created in the constructor.

It does get worse. Back in '99, I worked with a VB programmer who insisted on putting all the buttons on a form into one array, so they'd all have the same Click handler. He'd then use a big If-Then-Else block so that if the array index was 0, it was the Save button, and if the array index was 1, it was the Open button, etc.

See also GodClass, GodTable RRR


EditText of this page (last edited July 14, 2011) or FindPage with title or text search