The tag has no wiki summary.

learn more… | top users | synonyms

4
votes
0answers
30 views

Best practice for defining and keeping related stateless methods together in Objective-C

I have a few methods which are stateless: loginWithEmail: password: completion: signUpWithEmail: password: completion: resetPasswordForUsername: completion: Currently what I do is I create a class ...
1
vote
1answer
78 views

HashMap to replace Singletons?

Consider the following: I have controllers and views in a client-application. As this runs purely on the client side, each controller must only exist once. At first I thought about implementing ...
0
votes
0answers
38 views

What sort of design pattern should I be using here - Tabs Generation

I am fairly new with design patterns, I have been studying them but no practical experience so this is going to be my first try, Graphical representation of GUI is shown in this diagram, Points ...
1
vote
2answers
106 views

Joshua Bloch Enum Singleton and Third Party APIs

In the book Effective Java he give the best Singleton pattern implementation in his, that is implement by a Enum. I have doubt to how to implement this pattern with a third party API. I'm using an ...
2
votes
1answer
124 views

Where to keep persistent services in MVVM architecture?

In an MVVM application I need to use some services that are persistent, e.g. network services like P2P and WCF where the main "engine" or server endpoint must remain up and running during the lifetime ...
0
votes
1answer
99 views

Is having a Data Access Layer as singleton a good ideea

I'm working on a project(web application) where I have a DataManager(IDALContract dalImplementation) class that does some stuff with the data after retrieving it from the database or before saving it ...
0
votes
3answers
91 views

How should I refactor a singleton (to be used by a container) when the refactored class requires initialization and takes a dependency?

I'm refactoring an old app to use dependency injection.n I'm pretty new to DI. I have a class that used to be a singleton. I'm refactoring it into a non-singleton class and using the container to ...
3
votes
2answers
93 views

Does a serializable singleton imply both value and reference semantics at the same time?

I was reading Effective Java, and I came across passages that talk about ways you might implement a serializable singleton, as if this was a perfectly normal thing to do in Java. This immediately ...
2
votes
2answers
263 views

Is this the solution to static inheritance?

I've seen a lot of posts recently on why Singletons should be avoided. However, I can't see any of those problems with the following solution to a common problem: static inheritance. For example, I ...
0
votes
0answers
43 views

Will this singleton style class work with accessing a session on multiple MVC controllers?

Question background: I have an e-commerce site I'm developing that requires multiple controller methods to access a single session variable. The idea: My idea was to create a singleton style class ...
3
votes
2answers
193 views

Factory for creating a singleton instance

We have some legacy code that has a bunch of singletons all over the place (written in C#). The singleton is a fairly "classic" implementation of the pattern: public class SomeSingleton { ...
13
votes
3answers
2k views

Could a singleton type replace static methods and classes? [duplicate]

Possible Duplicate: What is the difference between all-static-methods and applying a singleton pattern? In C# Static methods has long served a purpose allowing us to call them without ...
1
vote
2answers
123 views

Is storing data that rarely changes in-memory a good candidate for a singleton/cache?

I have a class called DataPoint that is defined like the following. Currently, it goes through each property on an object and based on the DataPoint, it does some formatting like padding, trimming, ...
0
votes
1answer
95 views

Is it reasonable to use a decorator to instantiate a singleton in Python?

Suppose I have a class like this: class Foo(object): # some code here As it happens, Foo is a singleton. There are numerous ways to write singletons in Python, but most of them don't really ...
0
votes
1answer
135 views

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 ...
0
votes
1answer
253 views

How could I avoid singletons in this case? [duplicate]

Using Dart in the client part of a web app where I have an application manager that contains a List of application instances and references to services that are used by each application as in the ...
2
votes
1answer
183 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
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 ...
2
votes
1answer
167 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
33 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
370 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 ...
1
vote
0answers
106 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
178 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
232 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
267 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 ...
44
votes
5answers
4k views

When is Singleton appropriate?

Some hold that the Singleton Pattern is always an anti-pattern. What do you think?
1
vote
2answers
160 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
457 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
310 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
316 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 ...
12
votes
3answers
3k 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 ...
1
vote
6answers
2k views

Static classes and/or singletons — How many does it take to become a code smell? [closed]

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 ...
1
vote
3answers
147 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 ...
0
votes
1answer
187 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 ...
2
votes
3answers
712 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
898 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
863 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
663 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 ...
15
votes
3answers
10k 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 ...
16
votes
5answers
9k 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 ...
5
votes
4answers
2k 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 ...
-1
votes
3answers
491 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
389 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
415 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
254 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 ...
9
votes
4answers
5k 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 ...
3
votes
2answers
425 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 ...
1
vote
1answer
88 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
620 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 ...