Questions tagged [singleton]

The singleton is a design pattern to ensure that exactly one application-wide instance of a particular class exists.

Filter by
Sorted by
Tagged with
2
votes
1answer
758 views

Singleton Boost-based timer

I would like a review on this code, and how I could make it better. ...
7
votes
2answers
3k views

C++ shared_singleton

I actually feel bad posting "yet another singleton"... I wrote the following one many years ago and had recently found another application for it. We had many threads, each running the same function ...
5
votes
3answers
2k views

Storage class, dependency injection and singletons

In re-writing my PHP framework vervPHP, I've created the following class: ...
3
votes
1answer
1k views

Singleton with template wrapper

So far, I've used this in a few places and it seems solid. This is what I usually do to make a singleton: ...
3
votes
2answers
3k views

C++ templated singleton class - properly destroyed?

I have written a templated singleton class in C++ but I am afraid that it is not properly destroyed. Can you advise me on that ? my singleton.h ...
1
vote
2answers
17k views

Thread-safe singleton class using std::shared_ptr in C++(11) [closed]

What I am trying to accomplish is to create an efficient thread-safe singleton base class (as stated in the title). So this is my singleton class, which is used via inheritance (see below). ...
4
votes
1answer
2k views

Is this a good implementation of a thread-safe singleton using the observer pattern?

I need a singleton that can safely operate in a multi-thread environment. Threading and concurrency is new to me, so I'm not sure if this implementation holds. Take a look: ...
1
vote
1answer
318 views

Can this JavaScript singleton be improved?

I needed a singleton in JavaScript in order to make a DataManager which is called multiple times, but I just want it to load its data only the first time it is called, then give pieces of the data out ...
8
votes
1answer
1k views

JavaScript Boilerplate - Review comments required

I am in between to create JavaScript Boilerplate (collection of best practices around) for low/medium complex project and will host on GitHub in sometime once finalized it. Have divided the ...
4
votes
1answer
399 views

Singleton implementation using generics

I did this as an exercise just to practice/improve using generics. Independent of how useful this implementation of a Singleton is, how is my coding in terms of using generics and any other aspect of ...
7
votes
5answers
5k views

A generic singleton

What do you think about this for a generic singleton? ...
6
votes
3answers
2k views

Static methods or singleton?

I have class that handles HTTP requests: ...
1
vote
3answers
2k views

JavaScript singleton with methods and properties

I am diving deeper into JavaScript and starting to learn more about prototypes and simulating classes etc. I am used to working with the Module pattern and would like to try and combine this pattern ...
5
votes
1answer
5k views

Singleton class extending a parent class to utilise shared functionality

I have a singleton class which extends from an abstract java class. Two singleton classes extend from ItemImageThreadManager, the reason for this is to use shared ...
22
votes
2answers
25k views

Thread-safe Singleton class

I have created this class to simulate a thread-safe Singleton. Have I missed anything? ...
2
votes
1answer
558 views

How can I improve this code without using static or singleton? [closed]

I used to use static or singleton for my DAL class. However, I read some articles saying that singleton is evil and should be avoided. Therefore I try to rewrite my code like this: ...
3
votes
1answer
582 views

Singleton wrapper

Feel free to critique this database wrapper which is written as a code example for employers or clients. ...
4
votes
4answers
4k views

Singleton Decorator

I've written a class that makes writing singletons easy. The class is meant to be used as a decorator (example below). I'd like to see your thoughts about the code, the documentation, and everything ...
5
votes
5answers
858 views

Request for Comments: Singleton pattern implemented in Java

I have several utility classes who should only ever have one instance in memory, such as LogHelper, CacheHelper, etc. One ...
41
votes
7answers
3k views

Is my code a 'safe' singleton?

I was wondering if my code will produce a true singleton. I am creating an Android app, and all activities should access my API through one instance of the SyncApi ...
9
votes
3answers
2k views

Storing a Ruby app's settings

I have used code which looks a little like this in an app I'm working on: ...
67
votes
9answers
28k views

Implementing a Singleton pattern in C#

Is this the best way to implement this pattern in C#? ...

1 2 3
4