Questions tagged [singleton]

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

17 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
3
votes
0answers
102 views

JavaScript Singleton Pattern/Class “Methods”

I have a library that will be called in multiple places. Here is my implementation: var vessel1 = new Vessel(); var vessel2 = new Vessel(); ...
3
votes
0answers
178 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 ...
2
votes
0answers
58 views

SharedPreferences singleton wrapper

I was wondering wether my implementation of the PreferenceService below is thread safe or could cause memory leaks. Android Studio gives me the warning "Do not place Android context classes in ...
2
votes
0answers
65 views

Generic DialogueBox class with different parameters

I have implemented a DialogueBox class which can be static, singleton, service locator, etc. I have written it as a singleton pattern and implemented it in Unity3d engine. It is a part of a game. I ...
2
votes
0answers
35 views

Creating an object handler that loads objects in an array in PHP

I am creating tooltips that I will use throughout my site. Each individual tooltip is created as an object, all of these tooltips need to be ingested with these rules: I should be able to hold an ...
2
votes
0answers
166 views

Comments on singleton Swift status bar alert

I was trying out some projects like a status bar alert. It made most sense for this status bar to be a singleton: there is only one alert visible at a time. ...
2
votes
0answers
40 views

Classes to help transform “How hard is it to …?” questions into replies like “It's really hard to …”

I've written a Twitter bot, @answering_yelp, which responds to another Twitter bot, @hard_to_yelp. They scrape yelp reviews for sentences which start "How hard is it to..." and my bot answer with some ...
2
votes
0answers
50 views

Java interface to C library - Refactoring to singleton usage

I am currently writing a Java interface to a C library. It mostly just delegates calls and adds a object oriented layer on top of it to make integration into a regular Java program more natural. The ...
1
vote
0answers
138 views

Singleton pattern for Redis connection

Recently I have learned about singleton design pattern. I have tried to implement Redis connection following singleton design pattern. conn/redis.go ...
1
vote
0answers
160 views
1
vote
0answers
191 views

Singleton lock for a queue

This is a singleton class which can be accessed anywhere including the shouldLock variable. I want to make sure that the variable is thread safe. Basically the <...
1
vote
0answers
165 views

Using a singleton for a collection of discounts to calculate?

I'm wondering if using a Singleton for a storage of discounts is the right way to go. This is because I will be looping over all added discounts in another class. client code ...
1
vote
0answers
794 views

JavaScript to connect to Redis using Singleton

I'm trying to create a class to connect to Redis in Express. I don't think my code is good enough as I got variable db hanging out. ...
1
vote
0answers
189 views

JavaScript sound manager (singleton / static object using observer pattern)

I have some JavaScript code i would like your feedback on please. My goals: SoundManager should be a singleton/static class that has one instance. ...
1
vote
0answers
265 views

Claims authorization service usage

I'm doing an AuthorizationService. I'm not sure how to do the usage interface of this service, so that it's practical and handy. It doesn't necessarily has to be an ...
1
vote
0answers
164 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 (...
0
votes
1answer
2k views

Java MongoDB client as a singleton

Is below code a valid Singleton design pattern for Mongodb in Java? Please suggest any improvements. ...