God object
In object-oriented programming, a god object (sometimes also called an omniscient or all-knowing object) is an object that references a large number of distinct types, has too many unrelated or uncategorized methods, or some combination of both. The god object is an example of an anti-pattern and a code smell.
In object-oriented programming, a god object (sometimes also called an omniscient or all-knowing object) is an object that references a large number of distinct types, has too many unrelated or uncategorized methods, or some combination of both. The god object is an example of an anti-pattern and a code smell. import std; using std::string; using std::vector; class GameManager { private: vector players; int score = 0; bool running = false; public: GameManager() = default; ~GameManager() = default; void addPlayer(const string& name) { players.push_back(name); std::println("Added player: {}", name); } void listPlayers() const { std::println("Players:"); for (const string& p : players) { std::println(" - {}", p); } } void startGame() { running = true; score = 0; std::println("Game started!"); } void updateGame() { if (running) { score += 10; std::println("Score updated: {}", score); } } void endGame() { running = false; std::println("Game over! Final score: {}", score); } void draw() { std::println("[Rendering Game Screen]"); } void handleInput(const string& input) { if (input == "quit") { endGame(); } else if (input == "score") { std::println("Current score: {}", score); } else { std::println("Unknown input"); } } void saveGame() { std::println("Saving game state to disk..."); } void loadGame() { std::println("Loading game state from disk..."); } void run() { // ... } }; Instead, this could be more appropriately divided among separated responsibilities: import std; using std::string; using std::vector; class PlayerManager { private: vector players; public: PlayerManager() = default; ~PlayerManager() = default; void addPlayer(const string& name) { players.push_back(name); std::println("Added player: {}", name); } void listPlayers() const { std::println("Players:"); for (const string& p : players) { std::println(" - {}", p); } } }; class GameLogic { private: int score = 0; bool running = false; public: GameLogic() = default; ~GameLogic() = default; void startGame() { running = true; score = 0; std::println("Game started!"); } void updateGame() { if (running) { score += 10; std::println("Score updated: {}", score); } } int getScore() const noexcept { return score; } void endGame() { running = false; std::println("Game over! Final score: {}", score); } }; class Renderer { public: Renderer() = default; ~Renderer() = default; void draw() { std::println("[Rendering Game Screen]"); } }; class InputHandler { private: GameLogic& logic; public: explicit InputHandler(GameLogic& logic): logic{logic} {} ~InputHandler() = default; void handleInput(const string& input) { if (input == "quit") { logic.endGame(); } else if (input == "score") { std::println("Current score: {}", logic.getScore()); } else { std::println("Unknown input"); } } }; class SaveSystem { public: SaveSystem() = default; ~SaveSystem() = default; void saveGame() { std::println("Saving game state to disk..."); } void loadGame() { std::println("Loading game state from disk..."); } }; class GameManager { private: PlayerManager players; GameLogic logic; Renderer renderer; InputHandler input(logic); SaveSystem saves; public: GameManager() = default; ~GameManager() = default; void run() { // ... } };
References
- Chapter 3: Topologies of Action-Oriented Vs. Object-Oriented Applications · retrieved 2026-11-20 · rev 1352397558
Cite this reference
MLA "Chapter 3: Topologies of Action-Oriented Vs. Object-Oriented Applications." Riel, Arthur J. 2026-11-20. https://en.wikipedia.org/wiki/ISBN_(identifier). Accessed 24 November 2026.
Chicago "Chapter 3: Topologies of Action-Oriented Vs. Object-Oriented Applications." Riel, Arthur J. 2026-11-20. https://en.wikipedia.org/wiki/ISBN_(identifier).
APA Riel, Arthur J. (2026). Chapter 3: Topologies of Action-Oriented Vs. Object-Oriented Applications. Retrieved November 24, 2026, from https://en.wikipedia.org/wiki/ISBN_(identifier)
- Code Smell 14 — God Objects · retrieved 2023-03-05 · rev 1352397558
Cite this reference
MLA "Code Smell 14 — God Objects." Contieri, Maximiliano (2020-11-28). 2023-03-05. https://blog.devgenius.io/code-smell-14-god-objects-b84b75b702. Accessed 24 November 2026.
Chicago "Code Smell 14 — God Objects." Contieri, Maximiliano (2020-11-28). 2023-03-05. https://blog.devgenius.io/code-smell-14-god-objects-b84b75b702.
APA Contieri, Maximiliano (2020-11-28). (2023). Code Smell 14 — God Objects. Retrieved November 24, 2026, from https://blog.devgenius.io/code-smell-14-god-objects-b84b75b702
- Code Smell 14 — God Objects . · retrieved 2026-05-02 · rev 1352397558
Cite this reference
MLA "Code Smell 14 — God Objects ." 2026-05-02. https://en.wikipedia.org/w/index.php?oldid=1352397558. Accessed 24 November 2026.
Chicago "Code Smell 14 — God Objects ." 2026-05-02. https://en.wikipedia.org/w/index.php?oldid=1352397558.
APA encyclopegia.org. (2026). Code Smell 14 — God Objects . Retrieved November 24, 2026, from https://en.wikipedia.org/w/index.php?oldid=1352397558
Cite this article
MLA
"God object." encyclopegia.org, 2026, https://encyclopegia.org/wiki/god-object. Accessed 24 November 2026.
Chicago
"God object." encyclopegia.org. Accessed November 24, 2026. https://encyclopegia.org/wiki/god-object.
APA
encyclopegia.org. (2026). God object. Retrieved November 24, 2026, from https://encyclopegia.org/wiki/god-object
Accessed November 24, 2026 · CC BY-SA 4.0 · citation page · JSON