The singleton tag has no wiki summary.
7
votes
2answers
151 views
How to maintain synchronised state across threads - is this a good use for a Singleton?
I hear a lot about "Singletons are always bad" around the place. I don't hate on them to that degree but I try not to use them if I have a better alternative.
In this case I have a system that ...
0
votes
0answers
24 views
Not able to get a Database instance inside a Model class [migrated]
Does a class' __construct() method need to be public, in order to call a static method of this class inside of another class?
I'm trying to get a Database instance inside my Model class (MVC app), by ...
3
votes
2answers
106 views
Application Settings, Status and more as Singleton? [duplicate]
I am relatively new to programming (1yr field experience now) and I think that I am overusing the singleton pattern and I need some input on how to do it in a better way. Right now I am using ...
5
votes
2answers
212 views
How to avoid a singleton in this example?
I have a class Image and another one ImageStore. The Image it's just a value object containing the package name and the image name. The ImageStore does all the actual work: calculates the real path of ...
6
votes
2answers
362 views
Is there a name for this design pattern?
I don't like singletons, but I have to compromise now (but only as temporary measure).
However I don't want to go completely singleton. I'd rather want to use this pattern:
interface ...
3
votes
3answers
292 views
Why don't we use a class and its static members to do what a singleton does?
In Java,C++,Objective C, C#, and all other similar OOP languages,
Why don't we use a class with static methods and vars instead of going through a singleton syntax having to deal with various ...
5
votes
4answers
462 views
Is there something like a polymorphic Singleton?
I have a resource loader object that loads objects from the disk or from a ZIP archive, depending on the platform.
It has state (e.g. the path to the directory or the ZIP archive, and possibly some ...
1
vote
1answer
71 views
How to get a reference to a central AssetLoader in every Widget?
I'm working on a simple UI system for a game. The building blocks are Widget objects, which can contain each other. There are several sub classes of Widget, e.g. LabelWidget, ImageWidgetand ...
3
votes
3answers
332 views
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 ...
5
votes
3answers
268 views
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 ...
2
votes
1answer
245 views
What are the downsides of implementing a singleton with Java's enum?
Traditionally, a singleton is usually implemented as
public class Foo1
{
private static final Foo1 INSTANCE = new Foo1();
public static Foo1 getInstance(){ return INSTANCE; }
private ...
0
votes
5answers
324 views
should singleton be life-time available or should it be destroyable?
Should the singleton be designed so that it can be created and destroyed at any time in program or should it be created so that it is available in life-time of program. Which one is best practice? ...
3
votes
2answers
170 views
null values vs “empty” singleton for optional fields
First of all I'm developing a parser for an XML-based format for 3D graphics called XGL.
But this question can be applied to any situation when you have fields in your class that are optional i.e. the ...
2
votes
3answers
190 views
Name for Osherove's modified singleton pattern?
I'm pretty well sold on the "singletons are evil" line of thought. Nevertheless, there are limited occurrences when you want to limit the creation of an object. Roy Osherove advises,
If you're ...
3
votes
3answers
737 views
Is the singleton pattern prone to thread safety problems?
Is the singleton pattern prone to thread safety problems? If so, what are the best methods to work around them?
0
votes
0answers
64 views
Singletons in C++, are they really necessary, used? [duplicate]
Possible Duplicate:
When is Singleton appropriate?
Ok, most people probably know what a singleton is, use them, and know all the drawbacks including race conditions and so on.
But what I ...
0
votes
2answers
116 views
Template rendering engine legitimate use of a singleton?
I wrote a standalone singleton class (scaffold) tonight that serves as a facade to a few other classes, including a template class and a view class. Templates and views are both named and instances ...
0
votes
5answers
322 views
Does “Property” in C# cost much?
I have a class created in some namespace, like SomeNameSpace.SubNameSpace.StaticClassName
Here is a code snippet from other code file where I want to use this class many more times, so I created a ...
-1
votes
1answer
314 views
What is the difference between class level attributes, Class constants and singleton methods?
What the difference given they all exist 'once per class'.
When should I use one over another, i.e. for what purpose?
I use Ruby.
1
vote
1answer
401 views
const vs. readonly for a singleton
First off, I understand there are folk who oppose the use of singletons. I think it's an appropriate use in this case as it's constant state information, but I'm open to differing opinions / ...
14
votes
9answers
1k views
Alternatives to the singleton pattern
I have read different opinions about the singleton pattern.
Some maintain that it should be avoided at all costs and others
that it can be be useful in certain situations.
One situation in which I ...
11
votes
7answers
3k views
What are the roles of singletons, abstract classes and interfaces?
I am studying OOP in C++ and, even though I am aware of the definitions of these 3 concepts, I cannot really realize when or how to use it.
Let's use this class for the example:
class Person{
...
5
votes
4answers
369 views
C++ - Best way to have a central data repository
I'm coding in C++. I have a server that will have clients connect to it, and each client gets spun off into its own thread for communication. This server is hosting a game, so there is information ...
4
votes
1answer
391 views
DAO/Webservice Consumption in Web Application
I am currently working on converting a "legacy" web-based (Coldfusion) application from single data source (MSSQL database) to multi-tier OOP.
In my current system there is a read/write database with ...
2
votes
3answers
3k views
Static class vs Singleton class in C# [duplicate]
Possible Duplicate:
What is the difference between all-static-methods and applying a singleton pattern?
I need to make a decision for a project I'm working of whether to use static or ...
10
votes
4answers
2k views
Dependency Injection and Singleton. Are they two entirely different concepts?
I've been hearing about using the dependency injection over Singleton for my colleague. I still can't make out if it they are two orthogonal patterns which can be replaced with one another? Or is DI a ...
1
vote
3answers
246 views
Memory problems with singletons in a test suite
I am having a memory leak when running a test suite due to singleton objects are created and not cleared after each test case. And these singleton objects are holding references to heavy objects.
So ...
8
votes
4answers
394 views
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?
0
votes
1answer
94 views
Is using Singleton correct for Jtree & DefaultTreeModel?
Basically I have one Tree view which uses a single DefaultTreeModel.
Is it okay to use singleton for Tree extending JTree and another singleton for TreeModel extending DefaultTreeModel?
If not, what ...
1
vote
5answers
1k views
Static classes and/or singletons — How many does it take to become a code smell?
In my projects I use quite a lot of static classes. These are usually classes that naturally seem to fit into a single-instance type of thing. Many times I use static classes and recently I've started ...
11
votes
6answers
864 views
What to say to your boss if they want you to use a global variable
I am currently 4 months into an internship, and when reviewing my code, my boss didn't like that I had kept a specific object local to a number of methods across a few separate classes within one ...
18
votes
7answers
1k views
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 ...
7
votes
3answers
3k views
What is the difference between all-static-methods and applying a singleton pattern?
I am making a database to store information about the users of my website (I am using stuts2 and hence Java EE technology). For the database I'll be making a DBManager. Should I apply singleton ...
4
votes
2answers
261 views
Are the default objects of VB a type of singleton?
Are the default objects supported by My keyword in VB.net is a kind of singleton? If not, what is the difference?
Again is this "default object" feature is something useful? If yes, then why it is ...
10
votes
4answers
533 views
Does “notification center” pattern encourage good or bad program design?
Sometimes I come across these message-hub-style APIs, for example the Cocoa NSNotificationCenter: ...
23
votes
4answers
956 views
When is Singleton appropriate?
Some hold that the Singleton Pattern is always an anti-pattern. What do you think?