Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

When classes have no state, there's also really no need to have a singleton instance. If someone wants to instantiate a new object, who cares? It's a few extra cycles and a few more bytes in memory. Sure, you can have an easily accessible instance for convenience and performance, but nothing's going to hurt if somebody uses a different instance. Your program isn't compromised.

Singleton exists as a pattern to enforce a single instance because of state and side effects. What you're talking about is just a cached instance.



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: