Code Smell 60 - Global Classes

Subscribe to my newsletter and never miss my upcoming articles

Listen to this article

Classes are handy. We can call them and invoke them any time. Is this good?


  • Coupling

  • Classes are global unless we use Namespaces.

  • Name polluting

  • Static Methods

  • Static Constants

  • Singletons


  1. Use namespaces, module qualifiers or similar

  2. Avoid namespace polluting, keep the Global names as short as possible.

  3. Class single Responsibility is to create instances.

Sample Code



We can use almost any linter or create dependency rules searching for bad class references.


  • Globals


We should restrict our classes to small domains and expose just facades to the outside. This greatly reduces coupling.


More info


Photo by Alfons Morales on Unsplash

Write shy code — modules that don't reveal anything unnecessary to other modules and that don't rely on other modules' implementations.

Dave Thomas

This article is part of the CodeSmell Series.

No Comments Yet