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

learn more… | top users | synonyms

7
votes
4answers
245 views

Sound manager for Android

I created a singleton class for managing sound effects on Android. This class will only be instanced and loaded once at the beginning, and each activity will use the loaded songs. I don't know either ...
3
votes
1answer
66 views

Singleton With Sub-Singletons

I've found myself wanting an easy way to implement chat into various apps, so I developed a set of classes for the firebase.com backend that make it easy for me to quickly set up the nuts and bolts of ...
2
votes
2answers
251 views

Singleton design pattern

I am a beginner in PHP-OOP and design patterns. I have got this basic piece of code in Singleton Pattern and I changed it in order to understand its behavior. I can see that it works as expected. ...
6
votes
1answer
116 views

A parametrized Config singleton

Here is an attempt to code a specific kind of Singleton - the one geared for our configuration needs. It needs to be initialized with a configuration location, do not allow copies or other instances, ...
4
votes
1answer
147 views

ResourceManager Singleton

As I understand creating lots of resource managers in C# may be a bad idea so I thought that the best thing to do would be to create a singleton for this. However, I'm not 100% if this is a good ...
6
votes
2answers
129 views

Simple Java Singleton

Below is a Singleton that I designed as a piece of sample code for a website I'm working on for fun. The goal is to use the Singleton to hold an Earth object since ...
2
votes
2answers
146 views

Using a singleton class to get and set program wide settings

The following code works and does what I want, but I'd like to confirm I'm using this OOP concept correctly. I'm using the following class to get and set some configuration parameters for my program. ...
3
votes
1answer
65 views

How do I avoid explicit type switching when operation based on state?

I've encountered a problem that I have to solve using dynamic_cast to invoke different functions, depending on the type of class State family. I was re-factoring a ...
0
votes
2answers
430 views

PHP starting OOP MySQLi singleton

this is my first post on the whole StackExchange network, so I might make some mistakes. And I'm also spanish spearker, so I'll probably have mistakes in my writting too.. Context: I'm starting with ...
6
votes
4answers
147 views

Valid and safe use of SpinLock in Singleton?

Is this a valid and safe use of .NET's System.Threading.SpinLock? Why am I doing this? Random's public methods are not ...
0
votes
1answer
72 views

Creating a singleton container class for intrer-class messaging

My question is for validation of my code (any loop holes / bugs) and guidance the best methodology to implement for my requirement. I am developing a Python application that will have many classes. ...
2
votes
2answers
196 views

I need code review on using singleton to access local database

As I get to some performance issues in my app and find that I use database access in a bad way. So I decided to move to singleton pattern. I need someone to review this code and confirm me that I made ...
1
vote
1answer
214 views

JavaScript Singletons and Module Pattern [closed]

Is there a preferred way of doing what I describe here. I want to namespace my JavaScript code and use the Singleton Pattern so that only one instance of my JavaScript app exists. I have seen two ...
2
votes
1answer
130 views

Singleton has logic and state, and logic has state

------edit--------- note: this is for a MUD client, so the commands are issued to the MUD game server -----end edit-------- For an overview, here's the structure of the project: ...
1
vote
1answer
606 views

PDO class for multiple databases

I have PDO class below: ...
3
votes
1answer
225 views

A parent class, a singleton subclass, and a subclass uses a builder [closed]

There are three classes and an interface. The parent class is called MobileSignal. It contains info about mobile signal. E.g., CID, LAC, device ID, MCC, user ...
4
votes
3answers
2k views
4
votes
1answer
179 views

Prime Numbers Store

Problem definition: Lets say we need to create a store for selling prime numbers. Users enter the store and ask to buy a number. If the number asked is a prime number, 1.1. then it's either ...
0
votes
2answers
725 views

Singleton interface in Java

I've created a singleton by means of an interface. I don't want to make a thing with getInstance() etc because I don't care about inheritance, and it's redundant ...
2
votes
1answer
287 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
1answer
101 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: ...
5
votes
1answer
3k views

WPF Single Instance Best Practices

This is the code I implemented so far to create a single instance WPF application: ...
0
votes
2answers
199 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
2answers
400 views

Objective-C Singleton Implementation

is this the right way to do a singleton in Objective-C ? (coming from Android background, with a little understanding of threading) ...
1
vote
1answer
547 views

Why is android.app.Application not singleton by default [closed]

In many Android applications which I have found online or written myself, there is an application class like this: ...
4
votes
2answers
229 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 ...
1
vote
2answers
60 views

A Better Way To Write This Date Object?

In my program, I will only ever need one instance of this so I used a singleton Object. However, is there a better way to write this so I don't have to use so much wording when retrieving the ...
4
votes
1answer
449 views

Pubsub implementation using a Singleton

Is using a singleton to represent a Publish-subscribe message system a bad design choice? Background Im thinking about writing a pubsub implementation (using the singleton pattern) to allow for ...
4
votes
2answers
2k 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 ...
5
votes
2answers
565 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
567 views

Storage class, dependency injection and singletons

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

Review of C++ singleton

Originally posted on Stack Overflow. So far, I've used this in a few places and it seems solid. This is what I usually do to make a singleton: ...
1
vote
2answers
469 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
votes
2answers
4k 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). ...
2
votes
1answer
642 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
269 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 ...
2
votes
2answers
194 views

best way to use singleton [closed]

I know 3 ways for using singleton in our code and I want to know which one is the best way and you prefer more. The first is to have a Singleton class and every classes that want to be singleton ...
4
votes
2answers
676 views

Three-tier application with singleton pattern [closed]

I am creating a 3-Tier Windows Forms Application. Questions Am I using the right architecture, or can you suggest a better approach? Is there any way to make the base class be a Singleton? Is ...
8
votes
1answer
724 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 ...
3
votes
1answer
191 views

How is the design of this Singleton implementation

I did this as an exercise just to practive/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 ...
-1
votes
1answer
59 views

adding APL logger to an application [closed]

I have an application (Legacy code) that contains interface Icomponent with save() methods and many classes that implement it. ...
6
votes
4answers
411 views

A generic singleton - what do you think?

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

Static methods or singleton?

I have class that handles HTTP requests: ...
1
vote
3answers
401 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 ...
4
votes
1answer
2k 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 ...
14
votes
2answers
8k views
2
votes
1answer
322 views

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

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: ...
2
votes
1answer
418 views

Singleton wrapper

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

Python, 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 ...