Don’t create God classes.

These monsters try to do too much.

God classes control too many objects and contain far too much logic. They often don’t start out that way. Over time, additional methods and responsibilities are added and it grows and grows.

Watch out for classes that have too many responsibilities or dependencies. Another indicator is when a class is working with too many objects.

These monsters are hard to test, hard to maintain, and hard to document. As they become bigger, it’s hard to tell what’s really in them. Sometimes deprecated code lives on in them, which can get re-used by mistake.

Furthermore, the code is brittle. Because of the high number of dependencies, a god class may have hundreds of reasons to change.

Peel off responsibilities to other classes. It’s much better to have dozens of small classes than to have one classes that’s 10,000 lines long. In the end, it comes down to this: a class should really have one job.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: