The tag has no wiki summary.

learn more… | top users | synonyms

2
votes
1answer
121 views

Why use a enum to create the singleton pattern [duplicate]

Why would you use an enum to create a singleton pattern? To what purpose would it serve over a conventional singleton pattern? I have seen the above used. The code uses an enum to create this pattern ...
2
votes
1answer
134 views

Efficient Code Design for Pattern Search Using a Singleton Pattern

I am having difficulty figuring out an efficient (thread-safe) code design for the following problem. I have been at it for some time now and would really appreciate some advice and input on how best ...
0
votes
0answers
26 views

Designing Document class for Doc Imaging - optional fields

I'm working on a project that processes many Documents. A Document CAN have a Cover Sheet (if the first page is one) A Document CAN have a Stub (if Document is large) It matters whether or not a ...
1
vote
3answers
188 views

Why does dependency injection encourage collaboration to be exposed via constructors?

The general approach to DI that I see in answers like So Singletons are bad, then what? encourages business objects that collaborate with other objects to (a) not directly create those instances and ...
0
votes
0answers
69 views

Using Singletons in JS with workers

I'm building a javascript application that does continuous drawing, but relies on asynchronous scripts in the background which also need to poll for events and write to "global variables". This got me ...
1
vote
1answer
161 views

Do you use static keyword to declare single instance pattern? [duplicate]

I just come across this code and find it interesting to know whether you consider this as another single instance pattern? public class Initiator { private static String str; // there is many ...
0
votes
3answers
154 views

How to change the state of a singleton in runtime

Consider I am going to write a simple file based logger AppLogger to be used in my apps, ideally it should be a singleton so I can call it via public class AppLogger { public static String file = ...
1
vote
2answers
253 views

Is this a candidate for Singleton?

I have an external thermometer connected via USB that is controlled by my SW. Different parts of my system will use it but never at the same time (all in one thread). However, it is a single device ...
-6
votes
1answer
150 views

Does one really need multiple instances of a class? [closed]

Generally I'm extremely skeptical of anyone who criticizes the singleton design pattern in software. In the MVC (model-view-controller) design pattern, views and controllers are usually singletons and ...
1
vote
2answers
106 views

Passing central objects around or having global instances? [duplicate]

Having a larger WinForms application with several classes I currently pass references to several "central" objects around to function calls. This leads to more method parameters. Example: public ...
3
votes
3answers
324 views

Infinite loop with a singleton - does this type of issue have a name?

I ran into an unusual error while working on my project. To better learn from and remember it, I'd like to know if this type of error has a name or some definition. (The error itself OutOfMemoryError ...
0
votes
2answers
263 views

Java Singleton fields implementation

I have singleton in Java and I have realized, that I could make its fields static and it would work same way as regular instance fields. Would there be a performance / optimization difference? If ...
0
votes
0answers
228 views

Use a global variable, a singleton, or something else

Preface: I am working in PHP (Abandon hope all ye who enter here). Background: There exists a large set of global functions in PHP, a number of which are miscellaneous system calls, like sleep (and ...
0
votes
1answer
155 views

Singleton: Why is a global point of access bad? [duplicate]

Most people here and on StackOverflow agree that Singletons are evil. The main explanation I've come across against the use of Singletons, is they fact that they provide a global point of access to ...
1
vote
3answers
140 views

Simple Design for Singleton function in java for Kernel [closed]

I understand that Singelton helps to instantiate only one class AT A TIME. I try to learn how to Design for Singleton function in java. I want to know it better to understand Kernel. So I try to do ...
1
vote
3answers
293 views

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 ...
2
votes
1answer
524 views

MVC design, singleton in model with initialization

I've recently learned of MVC (model view controller) and am trying to refactor an existing program. I am in a situation where I'd like to have exactly one object of a particular class so it seemed ...
0
votes
1answer
403 views

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 ...
0
votes
2answers
419 views

Difference between Singleton pattern and auto_ptr<> resp. unique_ptr<>

I'm maintaining some legacy code of a physical simulation. The calculation object is build as a singleton, to ensure there is only one instance. A co-worker told me, that singleton are completely ...
14
votes
3answers
6k views

Static factory vs factory as a singleton

In some of my code, I have a static factory similar to this: public class SomeFactory { // Static class private SomeFactory() {...} public static Foo createFoo() {...} public ...
-1
votes
3answers
324 views

Is it possible to encapsulate the object itself within a dynamic property?

I ask this question out of curiosity. Lets say the class Foo is a singleton and I want to call Foo instead of Foo.Instance to access the static object. Would it be possible to encapsulate the ...
1
vote
4answers
2k views

Is it allowed to make multiple instances of a singleton class?

I am confused when I read this (regarding singleton design pattern): How do we ensure that a class has only one instance and that the instance is easily accessible? A global variable makes an ...
7
votes
2answers
345 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 ...
3
votes
2answers
340 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
247 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 ...
3
votes
2answers
417 views

Is there a name for this design pattern? [closed]

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
440 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
825 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
84 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 ...
5
votes
4answers
1k 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
1k 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 ...
10
votes
3answers
2k 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
456 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
606 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 ...
1
vote
3answers
238 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
2k 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
71 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
199 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
414 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
709 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.
2
votes
1answer
1k views

const vs. readonly for a singleton

I have a singleton that anchors together some different data structures. Part of what I expose through that singleton are some lists and other objects, which represent the necessary keys or columns ...
20
votes
9answers
5k 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 ...
14
votes
7answers
7k 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{ ...
6
votes
4answers
929 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
689 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 ...
3
votes
3answers
8k 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 ...
9
votes
4answers
4k 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
526 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
456 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
140 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 ...