God object

God object

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 several smaller problems (a divide and conquer strategy) and solutions are created for each of them. Once the small problems have been solved, the big problem as a whole has been solved. Therefore there is only one object about which an object needs to know everything: itself. Likewise, there is only one set of problems an object needs to solve: its own.

God object–based code does not follow this approach. Instead, most of a program's overall functionality is coded into a single "all-knowing" object, which maintains most of the information about the entire program and provides most of the methods for manipulating this data. Because this object holds so much data and requires so many methods, its role in the program becomes God-like (all-encompassing). Instead of program objects communicating amongst themselves directly, the other objects within the program rely on the God object for most of their information and interaction. Since the God object is referenced by so much of the other code, maintenance becomes more difficult than it would in a more evenly divided programming design.

A God object is the object-oriented analogue of failing to use subroutines in procedural programming languages, or of using far too many global variables to store state information.

While creating a God object is typically considered bad programming practice, this technique is occasionally used for tight programming environments (such as microcontrollers), where the slight performance increase and centralization of control is more important than maintainability and programming elegance.

See also

  • Ravioli code, the opposite pattern

Further reading

  • 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." 
  • Anti-Patterns and Worst Practices – Monster Objects

Wikimedia Foundation. 2010.

Игры ⚽ Нужно сделать НИР?

Look at other dictionaries:

  • God object — (deutsch: Gott Objekt ; auch: god class bzw. deutsch: Gottklasse) bezeichnet in der objektorientierten Programmierung ein Objekt, das zu viel weiß oder zu viel tut . Das God object ist ein Beispiel für ein Anti Pattern. Die grundlegende Idee der… …   Deutsch Wikipedia

  • God object — Un God object ou objet omniscient est, dans le domaine de la programmation orientée objet, un objet qui reconnaît trop de choses ou fait trop de choses. Le god object est un exemple d antipattern (ou anti patron). Sommaire 1 Description 2 Notes… …   Wikipédia en Français

  • Object (computer science) — In computer science, an object is any entity that can be manipulated by the commands of a programming language, such as a value, variable, function, or data structure. (With the later introduction of object oriented programming the same word,… …   Wikipedia

  • God — (g[o^]d), n. [AS. god; akin to OS. & D. god, OHG. got, G. gott, Icel. gu[eth], go[eth], Sw. & Dan. gud, Goth. gup, prob. orig. a p. p. from a root appearing in Skr. h[=u], p. p. h[=u]ta, to call upon, invoke, implore. [root]30. Cf. {Goodbye},… …   The Collaborative International Dictionary of English

  • God's acre — God God (g[o^]d), n. [AS. god; akin to OS. & D. god, OHG. got, G. gott, Icel. gu[eth], go[eth], Sw. & Dan. gud, Goth. gup, prob. orig. a p. p. from a root appearing in Skr. h[=u], p. p. h[=u]ta, to call upon, invoke, implore. [root]30. Cf.… …   The Collaborative International Dictionary of English

  • God's field — God God (g[o^]d), n. [AS. god; akin to OS. & D. god, OHG. got, G. gott, Icel. gu[eth], go[eth], Sw. & Dan. gud, Goth. gup, prob. orig. a p. p. from a root appearing in Skr. h[=u], p. p. h[=u]ta, to call upon, invoke, implore. [root]30. Cf.… …   The Collaborative International Dictionary of English

  • God's house — God God (g[o^]d), n. [AS. god; akin to OS. & D. god, OHG. got, G. gott, Icel. gu[eth], go[eth], Sw. & Dan. gud, Goth. gup, prob. orig. a p. p. from a root appearing in Skr. h[=u], p. p. h[=u]ta, to call upon, invoke, implore. [root]30. Cf.… …   The Collaborative International Dictionary of English

  • God's penny — God God (g[o^]d), n. [AS. god; akin to OS. & D. god, OHG. got, G. gott, Icel. gu[eth], go[eth], Sw. & Dan. gud, Goth. gup, prob. orig. a p. p. from a root appearing in Skr. h[=u], p. p. h[=u]ta, to call upon, invoke, implore. [root]30. Cf.… …   The Collaborative International Dictionary of English

  • God's Sunday — God God (g[o^]d), n. [AS. god; akin to OS. & D. god, OHG. got, G. gott, Icel. gu[eth], go[eth], Sw. & Dan. gud, Goth. gup, prob. orig. a p. p. from a root appearing in Skr. h[=u], p. p. h[=u]ta, to call upon, invoke, implore. [root]30. Cf.… …   The Collaborative International Dictionary of English

  • God — /god/, n., v., godded, godding, interj. n. 1. the one Supreme Being, the creator and ruler of the universe. 2. the Supreme Being considered with reference to a particular attribute: the God of Islam. 3. (l.c.) one of several deities, esp. a male… …   Universalium

Share the article and excerpts

Direct link
Do a right-click on the link above
and select “Copy Link”