God object

From Wikipedia, the free encyclopedia

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 structured 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.

God object–based code does not follow this approach. 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, or using far too many global variables to store state information.

While bad programming practice, a God object is occasionally created in tight environments such as microcontrollers where the slight performance increase is more important than maintainability. As microcontrollers increase in power, this should become less and less true.

In the 1970s, a God object in mainframe programming was known as the AECB, or all-encompassing control block.