Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

107
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda