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 creating a God object is typically considered bad programming practice, one is occasionally created in tight environments such as microcontrollers where the slight performance increase is more important than maintainability.
[edit] See also
- Riel, Arthur J. (1996). "Chapter 3: Topologies of Action-Oriented Vs. Object-Oriented Applications", Object-Oriented Design Heuristics. Boston, MA: Addison-Wesley. ISBN 020163385X. “3.2: Do not create god classes/objects in your system. Be very suspicious of an abstraction whose name contains Driver, Manager, System, or Subsystem.”