Video in progress
What is the "god object" anti-pattern and how do you recognize it?
A god object is one huge class that knows everything and does everything. It has thousands of lines and dozens of dependencies, and any change touches that class.
📖 Answer
The signs:
- the class has grown past 2–3 thousand lines, and its name is very generic:
Manager,Helper,CommonService,Utils; - 10+ dependencies are injected in the constructor;
- one class mixes methods that deal with users, payments, reports and email;
- every sprint several people change this file, and merge conflicts are constant.
Why it's bad: changes are risky (fix one spot and another breaks), tests are hard to write (you have to mock every dependency), and a new developer has a hard time understanding it.
How to split it in practice: group the methods by the data and dependencies they use. Usually the natural boundaries show up on their own: OrderPricing, OrderNotifications, OrderReporting. The realistic path isn't one day of work, but pulling out one piece with every relevant change.
Sign up to mark studied questions and save your progress.