Top "Singleton" questions

A design pattern that ensures that exactly one application-wide instance of a particular class exists.

How can I implement an abstract singleton class in Java?

Here is my sample abstract singleton class: public abstract class A { protected static A instance; public static A getInstance() { return …

java inheritance singleton abstract-class classloader
Is there a use-case for singletons with database access in PHP?

I access my MySQL database via PDO. I'm setting up access to the database, and my first attempt was to …

php oop design-patterns singleton
Why use a singleton instead of static methods?

I've never found good answers to these simple questions about helper/utility classes: Why would I create a singleton (stateless) …

java design-patterns singleton
Singleton lazy vs eager instantiation

If a singleton is implemented as follows, class Singleton { private static Singleton instance = new Singleton(); public static Singleton getInstance() { return …

java singleton lazy-initialization
Dependency Injection vs Service Location

I am currently weighing up the advantages and disadvantages between DI and SL. However, I have found myself in the …

c# dependency-injection singleton dependency-management service-locator
How is Meyers' implementation of a Singleton actually a Singleton

I have been reading a lot about Singletons, when they should and shouldn't be used, and how to implement them …

c++ design-patterns c++11 singleton
Singleton and unit testing

The Effective Java has the following statement on unit testing singletons Making a class a singleton can make it difficult …

java unit-testing singleton
Kotlin Singleton Application Class

So in android i want to make my application class a singleton. Making it like this: object MyApplication: Application(){} won't …

android singleton kotlin
What's Alternative to Singleton

We have a class that holds configuration information for the application. It used to be a singleton. After some architectural …

java design-patterns singleton
Serialize a Static Class?

What happens if we serialize a static class? Can more than one instance of the static class be created if …

c# serialization singleton