Most voted "singleton" questions
Singleton is a design pattern or design pattern that ensures there is only one instance of a class within the application, maintaining a global point of access to its object.
Learn more…30 questions
Sort by count of
-
75
votes3
answers4535
viewsWhy shouldn’t we use Singleton?
You finds on the internet the claim that Singletons are bad. Is this true? Why? Would the problem be generalized to any objects with single instance? Or to anything that has been global? If it is so…
-
11
votes4
answers277
viewsHow do the objects created following Singleton work?
I would like to understand how objects created work by following the Pattern Singleton javascript design. My main doubts refer to the methods and attributes of this object, where and how to create…
-
8
votes2
answers348
viewsSingleton in Javascript
How to implement the Singleton standard in Javascript in a simple and correct way - which assures me that the instance will be unique? I’ve seen somewhat complex implementations, but it wouldn’t be…
-
6
votes1
answer90
viewsUsing static factory methods instead of constructors
I’ve been doing some research on this subject after I read in Joshua Block’s book, Effective Java, Item 1, about the use of static factory methods rather than building builders. There in the text he…
-
5
votes2
answers4825
viewsHow to apply the Singleton pattern correctly?
The class PEHandlerService need to have a single instance and do not want to use synchronized because of the slowness, I developed the following code: public class PEHandlerService extends…
-
4
votes3
answers271
viewsHow to allow only one instance of a certain class?
If we execute the code below, a window will be created with a button inside, that every clicked will open another window (Window2)... How do I not allow a second instance of Window2? I want to do…
-
3
votes1
answer556
viewsFirebird C# standard Singleton
I am using the following function to connect to the database, I am programming in C# in Visual Studio 2013. namespace WindowsFormsApplication1 { static class Conexao { private static String strConn…
-
3
votes1
answer141
viewsIs there a pattern similar to Singleton?
It’s really frustrating, a little interesting maybe, but frustrating above all, just yesterday I figured out how and why to use the pattern Singleton, And today, as I was about to finish a little…
-
3
votes1
answer258
views -
3
votes2
answers153
viewsKeyword for C# equivalent to Java’s "Synchronized"
Problem I am implementing a connection manager that implements the standard Singleton, managing a pool connections with unique keys for each new connection. So I’m having problems with the…
-
3
votes1
answer4168
viewsHow to create a variable accessible in all Forms?
In my application you will have a login system. I want to create a variable to store the user id that is logged in, and that it can be accessed in all other forms. I need this because in my…
-
3
votes1
answer1442
viewsSingleton pattern causes error: Using $this when not in Object context
I made this Singleton pattern that I saw on a website and I thought it was great, just what I wanted. Yet something is going wrong because I have the mistake: Fatal error: Uncaught Error: Using…
-
2
votes1
answer411
viewsSingleton standard for database communication
In PHP when I do a Singleton is created an instance for each request that tries to open a connection to the database or instantiating a single time she "always" will stay in memory for all requests?…
-
2
votes1
answer1151
viewsWhat is English variable in English?
I’m doing a job on Prolog and when trying to make a query it says there are "Singleton variables". For example, a part of the code: s([Policia_X, Policia_Y, Ladrao_X, Ladrao_Y]) :-…
-
2
votes1
answer1197
viewsHow to understand this structure?
ContactHelper.internal(); static final ContactHelper _instance = ContactHelper.internal(); factory ContactHelper() => _instance; After an intense research on Factory methods and Singleton…
-
2
votes2
answers482
viewsAvoid permanent connections and Singleton class in a PHP project
I am developing a CMS with PHP and using the MVC standard, without using frameworks, I know many will say that I should not do this, but I am doing this as a form of study. However, I never really…
-
2
votes1
answer59
viewsSingleton implementation static member error
When implementing the Singleton standard the compiler gives the following error: include graphdata. h|21|error: 'constexpr' needed for in-class initialization of Static data Member 'graphdata*…
-
1
votes1
answer448
viewsApplication of the Singleton standard for small/large design
I’m building classes for an old project where I used only functions in different files. The goal is clear, to create a reusable code standard for small-scale projects with not very distinct…
-
1
votes1
answer448
viewsSingleton standard
I am creating a project in C# and WPF, and I need to control instances of WPF windows, IE if I open a window in a code part with wndJanela.Show(), I want that when calling the Show() method again…
-
1
votes0
answers212
viewsReturn a variable (Singleton) using Node that depends on Promise
Good afternoon, you guys, It has to create a variable in Nodejs/JS where I would return a value only to be used several times throughout the program? Exemplifying my problem: I have to log on to a…
-
1
votes1
answer46
viewsWhat is the advantage of having a single instance when using the Singleton standard in web development?
Researching a little more about Singleton I found some comments in favor and against the use of this approach. But I still doubt the usefulness of instantiating a single instance of a class (and…
-
1
votes1
answer597
viewsDesign Standards: Singleton Design Standards
I know that the Singleton guarantees me a single instance of a given object. I understood this. What creates doubt would be its use in practice like this. Let’s assume the code below, using…
-
1
votes1
answer38
viewsReturning error in insert function
Good morning. My function is returning an error, but I don’t know what you mean, I used the Singleton standard to do, so I will post 2 codes: <?php class IndicadoDAO{ private $idIndicado; private…
-
1
votes1
answer45
views.NET Core - Class configured in container with Addsingleton() needs to be a Singleton?
A Web API application in . NET Core consumes a DLL in . NET Standard. DLL has a Foo class that depends on the Bar class: class Foo { private readonly IBar bar; public Foo(IBar bar) { this.bar = bar;…
-
0
votes1
answer64
viewsInstance of database connection
People, I have a problem which is this, my database connection class is a Singleton. It happens that if the server drops the instance of the class does not know that the server is down, I only know…
-
0
votes1
answer397
viewsGlobal variable data getting lost Android
Hello to all I’m creating an app that when the person logs in, the app brings the data Nome, Login, Senha and Foto(a url) of the server database, and saves that data in a Singleton so that they are…
-
0
votes0
answers122
viewsAndroid - Create a Socket in Singleton
Good night, I’m developing an android game where to play online have to connect to the server. At first I was trying to create sockets in an Activity where the game will occur, but the app was…
-
0
votes2
answers254
viewsProblem when compiling c++ Singleton
When I’m trying to compile a singleton I always get the following return message: g++ -g -Wall pkg-config --cflags stage -fPIC pkg-config --libs stage -c -Wall Connection.cpp cc Connection. o -o…
-
0
votes0
answers137
viewsStandard Singleton in simultaneous connections
I’m developing a project and I made a class in the pattern Singleton to connect to the database: <? class Conexao extends PDO { private static $instancia; public function __construct($dsn,…
-
0
votes2
answers324
viewsSingleton pattern in Python
I was watching this article on how to create Singleton classes in Python (among many others), I found unnecessary so much programming technique for a really simple thing. Of course I could be wrong.…