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
1 answer
2k views

Abstract class which uses a abstract factory -> New implementation with Singleton

I have a abstract class which is extended by many many other classes: What I have done: ...
sk2212's user avatar
  • 185
1 vote
1 answer
1k views

Mixin both instance and class methods in Ruby

I have a Ruby class into which I want to include both class and instance methods. Following the pattern described in "Ruby Pattern: Extend through Include", I'm currently using the following: ...
user2398029's user avatar
31 votes
1 answer
29k views

Single-instance WPF application

This is the code I implemented so far to create a single instance WPF application: ...
Tommaso Belluzzo's user avatar
1 vote
1 answer
353 views

PHP my way of threating static classes

A few days ago I've faced an annoying problem. Let's imagine we have 3 classes: Base, System, Handler. The classes Systen and Handler both inherit from the class Base. I want to access those classes ...
maximkott's user avatar
  • 113
2 votes
2 answers
817 views

Objective-C singleton implementation

Is this the right way to do a singleton in Objective-C (coming from an Android background, with a little understanding of threading)? ...
David T.'s user avatar
  • 151
3 votes
2 answers
338 views

Objective-C retain / release snippet

Here are some snippets I coded and I would like some feedback on my way of handling this: I have a utility class, as a singleton, that provides me with a method named ...
Andy M's user avatar
  • 141
9 votes
4 answers
24k views

Threadsafe DBContext in singleton

I found out the hardway that access to DbContext in .NET is not threadsafe. I have a singleton for logging things using a dbcontext. The original version uses something like ...
Martijn's user avatar
  • 585
2 votes
1 answer
878 views

Singleton Boost-based timer

I would like a review on this code, and how I could make it better. ...
Matthew Hoggan's user avatar
7 votes
2 answers
4k 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 ...
screwnut's user avatar
  • 289
5 votes
3 answers
2k views

Storage class, dependency injection and singletons

In re-writing my PHP framework vervPHP, I've created the following class: ...
EvilChookie's user avatar
3 votes
1 answer
2k 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: ...
defube's user avatar
  • 243
3 votes
2 answers
4k 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 ...
Patryk's user avatar
  • 305
1 vote
2 answers
20k 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). ...
Joseph Floyd's user avatar
4 votes
1 answer
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: ...
soren.qvist's user avatar
1 vote
1 answer
326 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 ...
Edward Tanguay's user avatar
9 votes
1 answer
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 ...
Mohammad Arif's user avatar
4 votes
1 answer
434 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 ...
Aaron Anodide's user avatar
7 votes
5 answers
7k views

A generic singleton

What do you think about this for a generic singleton? ...
Simon Hughes's user avatar
6 votes
3 answers
2k views

Static methods or singleton?

I have class that handles HTTP requests: ...
Dmitry Zaytsev's user avatar
1 vote
3 answers
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 ...
ngr's user avatar
  • 125
5 votes
1 answer
6k 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 ...
blue-sky's user avatar
  • 557
22 votes
2 answers
25k views

Thread-safe Singleton class

I have created this class to simulate a thread-safe Singleton. Have I missed anything? ...
q0987's user avatar
  • 321
2 votes
1 answer
565 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: ...
walterhuang's user avatar
3 votes
1 answer
589 views

Singleton wrapper

Feel free to critique this database wrapper which is written as a code example for employers or clients. ...
user avatar
4 votes
4 answers
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 ...
Paul's user avatar
  • 242
5 votes
5 answers
979 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 ...
user avatar
41 votes
7 answers
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 ...
jjnguy's user avatar
  • 671
9 votes
3 answers
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: ...
bluekeys's user avatar
  • 255
67 votes
9 answers
29k views

Implementing a Singleton pattern in C#

Is this the best way to implement this pattern in C#? ...
Aim Kai's user avatar
  • 772

1 2 3
4