Linked Questions

618 votes
13 answers

So Singletons are bad, then what?

There has been a lot of discussion lately about the problems with using (and overusing) Singletons. I've been one of those people earlier in my career too. I can see what the problem is now, and yet, ...
Bobby Tables's user avatar
  • 20.6k
38 votes
3 answers

When to use a Singleton and when to use a static class [duplicate]

I've searched about this here and on StackOverflow and found some differences between the two. But I'm still not sure in what cases one would prefer a Singleton, and in what cases one would choose to ...
Aviv Cohn's user avatar
  • 21.4k
26 votes
7 answers

The Singleton Pattern [duplicate]

Possible Duplicate: When is Singleton appropriate? I am a new programmer (4 months into my first job) and have recently taken an interest in design patterns. One that I have used recently is the ...
Darren Young's user avatar
  • 2,175
-6 votes
1 answer

Singleton: Is Singleton an Anti-Pattern [duplicate]

Was reading an interesting blog post on Singleton design pattern which is so widely used. If it's stupid or as in some quora posts, its an anti-pattern why is it so widely used even in frameworks. ...
bschandramohan's user avatar
8 votes
4 answers

Is there is a case when there is no any reasonable replacement for singleton design pattern? [duplicate]

Possible Duplicate: When is Singleton appropriate? I've seen many explanations why is Singleton is evil. But is there really no such a case when Singleton is the only beautiful solution?
eigenein's user avatar
  • 181
1 vote
1 answer

Why singleton is an anti-pattern? [duplicate]

Many articles in Internet say that singleton is an anti-pattern, because it makes debugging more difficult. However I don't understand why debugging a program with a singleton object is difficult. ...
porton's user avatar
  • 761
0 votes
1 answer

Why use the Singleton pattern over class functions and fields? [duplicate]

I'm going to start by saying that I understand that programming in mostly class functions and variables can be harmful to object-orientation, and that most of the time an instance is preferred. I'll ...
Ky -'s user avatar
  • 545
12 votes
6 answers

Are immutable/stateless singletons bad?

Lately there have been some kind of revolution against singletons, but is there something wrong with them if they are stateless? I know the overuse talk and all... this applies to everything not just ...
Random42's user avatar
  • 10.5k
7 votes
3 answers

How to create a manager class without global variables nor singletons?

I would like to implement some kind of manager class in my application. It will be in charge of loading textures, processing them, distributing them etc... At first, I wanted to make a global ...
Saturn's user avatar
  • 3,907
8 votes
5 answers

Should methods that are not "pure functions" and that interact with external APIs or hardware be static?

When reading about when to make a method static or not, I've seen a general principle, as summarized by this post, that a method should only be static if it does not modify a state and its result ...
adjordan's user avatar
3 votes
5 answers

How do Singletons differ from Static variables?

Although I do find some (apparently old) posts on the topic on the web, I could not find one here at SE. Thought of raising this here to see if what I read is accurate/is all there is to it. So ...
Veverke's user avatar
  • 461
5 votes
1 answer

DB Object passing between classes singleton, static or other?

So I'm designing a reporting system at work it's my first project written OOP and I'm stuck on the design choice for the DB class. Obviously I only want to create one instance of the DB class per-...
Stephen's user avatar
  • 53
5 votes
2 answers

What alternatives to a singleton are there for a class which only can have one instance?

I need to represent an abstraction over various parts of the hardware for a game. I'm trying to decouple the code that does things like manage the logic of the game from the code that is API/platform ...
user112513312's user avatar
2 votes
2 answers

Is it good OOP practice to pass object to object and have more than one instance of class?

Singleton pattern saying "there should be no more than one instance of same class", is this something one should stick to when designing PHP OOP applications? What are advantages / disadvantages? ...
Ananas's user avatar
  • 117
6 votes
1 answer

Using module level declared global "singletons" in python

Ok, I know that using singletons is generally a bad practice, but if I do it (for db connection, logging et al.) am I allowed to go (in respect of clean design) with a module defined variable that is ...
zeller's user avatar
  • 161

15 30 50 per page