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

learn more… | top users | synonyms

-1
votes
0answers
27 views

Any defect / suggestion in my logging mechanism (c++) [on hold]

Link: https://github.com/debdipta/designpattern/tree/master/singletone In above link I have wrote one opensource logging mechanism. It is in c++ and using Singleton design pattern!!! I was thinking ...
0
votes
0answers
37 views

Ingest data from an RDBMS to Hadoop Hive database using Sqoop

Context: The below code will run a series of steps in an ETL workflow. I would like the code to be reviewed to avoid memory bottlenecks and null pointer exceptions etc. UseCase: Ingest the data from ...
6
votes
1answer
89 views

Generic singleton array with archiving and insertion functions

I find that I often have to maintain a singleton primarily to hold an array that is sometimes persisted between user sessions, that should have only one class of items, and that sometimes needs to be ...
2
votes
1answer
91 views

Singleton Class for WordPress Plugin

I'm developing a WordPress plugin using the singleton pattern with the following requirements: There should ever exist one instance of the plugin Another instance of the object should never be ...
5
votes
2answers
91 views

Loading Configurations from plist into singleton

In my iOS application, I've created a singleton class that reads a configuration plist file and provides accessor methods to easily retrieve the values: ...
3
votes
0answers
34 views

Threadsafe singleton factory to use in Apache thrift server RPC system

My goal was to write a factory that the code did not have to be edited. Thus I am registering my factory functions into a singleton factory. I am going to be using this code in Apache thrift server ...
1
vote
1answer
48 views

Application Configuration in PHP

I'm learning PHP and I know too many ways to configure the application. I use this method: Folder: app config app.php db.php src class.php index.php ...
2
votes
1answer
85 views

(Y.E.S.E.J.) Yet Another Singleton with Enum in Java

I have a Java class which has to be generated only once for all the objects that I have - it is a small program. This singleton class holds a mapping of characters. I Googled stack overflow and found ...
6
votes
1answer
80 views

Android app with config and customization classes

I have an Android app with three different Activity classes. Each of the Activities uses and changes config and user-customization data stored in a wrapped ...
6
votes
2answers
146 views

Singleton-ish RMI Server

In this program there is a single remote server which performs miscellaneous work. Because there is only one server, it seems like a singleton pattern could fit well. The problem that a distributed ...
6
votes
1answer
69 views

Creating an in-memory ViewCounter that commits to database every 10 minutes

This singleton is responsible for counting every pageview (called Routes in our case) we get by id, until the timer runs out and commits the results to the database in one query. Then the counter gets ...
2
votes
1answer
127 views

Global.asax singleton

Please help me decide whether this should be good or bad idea to declare a Singleton variable in Global.asax file. (It is not actually singleton pattern, I just want to make sure that only one ...
3
votes
1answer
163 views

Singleton base class

I just wrote a singleton base class for a hobby project I'm currently working on. Python is not my first language, which is why I am not sure if everything is done the pythonic way. I also used ...
3
votes
2answers
232 views

Manage Sessions within a Singleton

I am looking for advice if the below code is a good idea or not. If not, why? I am building a website which allows a user to purchase items. The user account and cart items will be stored in Session. ...
2
votes
1answer
37 views

Javascript singleton to notify different objects of changes in viewport size

I'm working on a singleton object to manage size changes in the viewport, I wanted it to be a singleton because there may be different unrelated objects that need to be notified when a change in ...
2
votes
1answer
50 views

Persisting data between HttpRequests in MVC

IMetadata ...
6
votes
2answers
203 views

Building in the built-in declarations

In order for Rubberduck to be able to "recognize" the built-in VBA functions, procedures and objects, I added yet another constructor parameter to my Declaration ...
1
vote
1answer
152 views

Dependency injection thread safety

Is it OK to mix different lifetime of ISerializer and ICacheProvider in this case? I am using Unity DI. In this case, whenever ...
0
votes
1answer
156 views

Ruby singleton for logging

I currently have a logging setup that looks like this: ...
0
votes
1answer
989 views

A Singleton Base and derived class

I have a base and derived class since I need to have different kinds of concrete classes. I cannot use the getInstance() function in the base class since I cannot ...
3
votes
1answer
130 views

Reducing lock contention for a caching utility, or make it totally lockless but threadsafe

My Java program is a module called configProxy which fetches configuration entries from a remote node (say from a Redis instance). When the caller calls the ...
30
votes
4answers
22k views

Swift 1.2 Singleton Implementation

I am pretty new to Swift, as a solo developer I was wondering if somebody could pass comments on the singleton implementation below. The code does work, but being new to Swift and knowing that there ...
4
votes
1answer
144 views

Correct usage for singleton and reusability?

I've made the following DataSetReader, DS Attribute, and DataSetManager. My main concerns ...
5
votes
3answers
726 views

Design of a remoteControl class for connecting to electronic devices

In a course that I'm taking on learning object oriented programming in java, I have completed an assignment for modeling a home entertainment system and the ability for a user to be able to use a ...
0
votes
1answer
163 views

PHP framework building: initializer and object loader classes

I am building a PHP framework and would like to get some feedback on a few different sections of the project. I consider myself still a neophyte in PHP so I would like to ask if I'm going about ...
1
vote
1answer
46 views

Managing a collection of object instances and getting them back out with instance manager / service locator

I'm creating an event loop for an asynchronous event execution library for PHP in PHP. Note that this is for a library and not an application. My event loop is just that -- a simple event loop that ...
3
votes
1answer
96 views

Execute startup method asynchronously

The goal is to call startManager on application start so that the manager is initialized in background without blocking application main thread. Is it a safe ...
12
votes
1answer
120 views

Storing messages for the application's runtime

I am currently writing a well.. manual testing site for a chat-based bot. The full code can be found on github. For that purpose I had to keep track of the messages currently in the "system". The ...
3
votes
1answer
170 views

Blocking builder with singleton

I am trying to implement a singleton builder that would be shared across multiple builder threads for Coordinate objects. Here is the simplified target class ...
3
votes
1answer
234 views

Ensure only a single instance of static template class member

I am interacting with a C library, whose documentation states that certain functions are not thread safe. Since its functions deal heterogeneously with multiple types, I have written a template ...
1
vote
0answers
96 views

Singleton request validator and sanitizor class

I have tried to code a PHP singleton class for validating multiple/single fields (sanitizing is optional). When validating single field, on success it will return 1 (...
5
votes
2answers
645 views

Thread-safe Phoenix Singleton class template with Boost

I've implemented the phoenix-singleton as a class template with boost inspired by Modern C++ Design. The code compiles fine with MSVC 2013 - and it seems to work, but I'm new to multi-threaded ...
8
votes
1answer
2k views

Can we now `implement Singleton` using Java 8?

After my success with extending enum - I thought I would try to make Singleton creation as simple as possible since Java-8 makes ...
1
vote
2answers
488 views

Proper way to wait end of a service and singleton design

My code works fine and I would like to know if I chose the best strategy to implement my code, or if It can written better (more fast, more clear, best use of design pattern, etc). In my android ...
2
votes
1answer
178 views

Lazy singleton with BackboneJS

I am trying to have a Backbone.Model which is a singleton and I wish to instantiate it lazily. I only need to support modern browsers so please do not worry about the use of ES5 getter. Is this the ...
10
votes
5answers
5k views

Singleton Database class

Currently my team is building an application involving a database. We have to write a lot of data (approx 2,000,000 records) to the database and therefore we decided to open a connection once and ...
8
votes
3answers
650 views

Singleton Database wrapper

Before everybody yells at me about why I wrote a PDO wrapper class, it's to avoid writing try/catch, ...
3
votes
2answers
1k views

Correct way to implement a Singleton field

I have a helper class that does HTTP operations on Android. Every method uses a client field. I think it's a good idea to make this client a singleton since every method in the class uses it. The ...
4
votes
2answers
1k views

Singleton necessary in DAO

I am using a singleton in my DAO. Would I be better with static methods? Also, should I be worried about synchronization of the singleton and my data statures? ...
4
votes
2answers
158 views

Address book with singletons

My main goal with this refactor was to change instance methods that should have been class methods in the first place into class methods. My secondary goal was to add singletons to these classes ...
4
votes
2answers
81 views

Static variable representing program state accessed with multiple functions

I have this method that performs certain functions based on the state that the algorithm is currently at: ...
2
votes
2answers
1k views

PHP Trait Singleton

An implementation of the singleton pattern in PHP using a trait (added in 5.4). Is there anything missing, any ways to create a second copy of the class? ...
6
votes
1answer
1k views

Searching for songs on an Android application

In my application I need to search for some songs on my external storage card every now and then. On startup I read everything, however when it comes to new activities I thought I could just pass the ...
5
votes
2answers
635 views

Android global data

I have a huge list of song objects in my program and I need those objects in almost all activities. Well, at least a part of it up to everything. So I created a class which looks pretty much like ...
5
votes
3answers
409 views

Is this good design for custom email template?

I read effective Java by Joshua Bloch. And it said use enums over int constant. So I was thinking instead of using hard coded strings I could also use enums. The forgotpassword.txt and ...
6
votes
1answer
103 views

Manage a collection of settings in memory with global scope

I have a WPF app and a bunch of read/write settings that need to be accessible from various view models. a setting can be any type (string, ...
0
votes
1answer
111 views

Singleton-like pattern for a project [closed]

I'm changing the inner implementation of a project. In order to do so, I've created an interface that will be implemented in 2 different ways. One of this ways is by class ...
6
votes
4answers
3k 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
259 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 ...
6
votes
2answers
423 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. ...