Code Smell 14 - God Objects

Subscribe to my newsletter and never miss my upcoming articles

An object that knows too much or does too much.

Problems

  • Cohesion

  • Coupling

Solutions

  • Split responsibilities.
  • Follow Single Responsibility Principle.
  • Follow The Boy Scout Rule.

Examples

  • Libraries

Exceptions

Sample Code

Wrong

Detection

Linters can count methods and warn against a threshold.

Tags

  • Cohesive

Conclusion

Libraries were fine in the 60. In Object-Oriented Programming we will distribute responsibilities among many objects.

Also Known as

  • Large Class

More info

Credits

Photo by Francisco Ghisletti on Unsplash


This article is part of the CodeSmell Series.

No Comments Yet