God object

From Free net encyclopedia

Revision as of 16:24, 18 December 2005; view current revision
←Older revision | Newer revision→

In object-oriented programming, a God object is an object that knows too much or does too much. The God object is an example of an anti-pattern.

The basic idea behind OO programming is that a big problem is broken down into many smaller problems (divide and conquer) and solutions are created for each of them. If you are able to solve all of the small problems, you have solved the big problem as a whole. Therefore there is only one object about which an object needs to know everything: itself. And there is only one problem an object needs to solve: its own.

Poor code does not follow this approach to creating a solution. Instead, much of a program's overall functionality is coded into a single object. Because this object holds so much data and has so many methods, its role in the program becomes God-like (all-encompassing).

Instead of objects communicating amongst themselves directly, the other objects rely on the God object. Because the God object is referenced by so much of the other code, maintenance becomes more difficult than it otherwise would.

A God object is the object-oriented analogue of failing to use subroutines in procedural programming languages.