Questions tagged [singleton]
The singleton is a design pattern to ensure that exactly one application-wide instance of a particular class exists.
179
questions
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:
...
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:
...
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:
...
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 ...
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)?
...
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 ...
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
...
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.
...
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 ...
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:
...
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:
...
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
...
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).
...
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:
...
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 ...
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 ...
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 ...
7
votes
5
answers
7k
views
A generic singleton
What do you think about this for a generic singleton?
...
6
votes
3
answers
2k
views
Static methods or singleton?
I have class that handles HTTP requests:
...
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 ...
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 ...
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?
...
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:
...
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.
...
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 ...
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 ...
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 ...
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:
...
67
votes
9
answers
29k
views
Implementing a Singleton pattern in C#
Is this the best way to implement this pattern in C#?
...