Dev Genius

Coding, Tutorials, News, UX, UI and much more related to development

Follow publication

Code Smell 60 — Global Classes

Maximiliano Contieri
Dev Genius
Published in
2 min readJan 31, 2021

Photo by Alfons Morales on Unsplash

Problems

  • Coupling
  • Classes are global unless we use Namespaces.
  • Name polluting
  • Static Methods
  • Static Constants
  • Singletons

Solutions

  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

Wrong

Right

Detection

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

Tags

  • Globals

Conclusion

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

Relations

More info

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

Dave Thomas

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

Published in Dev Genius

Coding, Tutorials, News, UX, UI and much more related to development

Written by Maximiliano Contieri

I’m a senior software engineer specialized in declarative designs. S.O.L.I.D. and agile methodologies fan. Maximilianocontieri.com

No responses yet

Write a response