Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Singletons

Options
  • 15-06-2007 6:19pm
    #1
    Registered Users Posts: 1,481 ✭✭✭


    So I've been reading up a bit on people's criticisms of the use of Singletons in C++, and how it breaks the object oriented paradigm due to being just a fancy wrapper for global variables, which is fair enough. The other complaints also make sense such as a lack of clear ownership, introducing dependencies in the code that use them, and no way of handling dangling Singleton pointers.

    However in all the rants I've read about Singletons, nobody suggests a viable alternative. We use them fairly extensively here for being a central point to manage various features and resources, and they work pretty well for what they do. Granted, if we ever wanted to remove Singletons and change to some other pattern, refactoring would be a nightmare given the amount of code in our codebase that is dependent on them - although I'd imagine this would be a problem no matter what patterns we used. But otherwise, their use is clearly defined and they are constructed and destructed in known places and nowhere else.

    There are bound to be some "singletons are the spawn of the devil" people lurking here; I'd be interested in hearing exactly why they feel that way and what alternatives they suggest.


Comments

  • Registered Users Posts: 995 ✭✭✭cousin_borat


    Interesting post. Generally with Java I stick to Design Patterns that avoid the use of Singleton variables.

    However when programming in PL/SQL it is very difficult to avoid using them. I'll get around sometime to looking for sources which don't. However the much of the internal Oracle internal code uses singletons.


Advertisement