Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

111
Vistas
Does a singleton with only one public method make sense?

I have a class that exposes only one public method and it's a singleton.

Would it make sense to just get rid of the class thing and declare properties and methods as global variables and functions? And then exporting only the one "public" function.

Is there anything wrong about using global variables?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

In general, avoid the singleton pattern altogether if your class has state, since that becomes global state. But if you can't (easily):

Can I get rid of the class thing and declare properties and methods as variables and functions? And then exporting only the one "public" function?

Yes, this makes total sense with modules. A module is essentially a singleton already (it gets evaluated only once). Notice the variables and functions wouldn't be global, they're scoped to the module.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda