Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

109
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!