singleton

Which is more evil: an unnecessary singleton or a God Object?

Here's the situation: I've got a class that is doing too much. It's mainly for accessing configuration information, but it also has the database connection. It's implemented as a singleton, so this also makes unit testing it difficult as most code is pretty tightly coupled to it. This is even more problematic as it creates an import-...

Multi-variable complicated singletons

I have a pair of static fields with a complicated one-time initialization. I want this initialization to happen lazily, a la the standard singleton pattern. However, the initialization procedure involves both fields, so I can't separate it into two different singletons. What's the best way to handle this? ...

Question about non-static members of a singleton (C#)...

Hey folks, I have a question about singletons that I think I know the answer to...but every time the scenario pops-up I kinda second guess myself a little so I would like to know the concrete answer. Say I have two classes setup as so... public class ClassA { private static ClassA _classA; public static ClassA Instance { ...

Singleton and Abstract base class in C++

Recently I got question on implement Singleton but abstract base class involved. Suppose we have class hierarchy like this: class IFoo {...}; // it's ABC class Foo : public IFoo {...}; we have singleton class defined as follows: template <typename T> class Singleton { public: static T* Instance() { if (m_instance == NULL) { ...

Singleton Pattern in VBScript (Classic) ASP

I've just created a Classic ASP version of the FirePHP server side library, that works with the regular old FirePHP console. see the Github project However in my implementation, i have to create a global to store the class instance. I have no idea how to, if it is even possible to create static methods, and thus use the singleton patt...

Best practices for Singletons and Notifications on the iPhone

Hey guys, Just to give background for my situation, I have a manager singleton that pulls data from a webserver and provides access to the downloaded data. I have several types of views that will consume this data, but only one view at any time will need to receive events. I was just wondering what people prefer to use when they need t...

Given the recent trends in TDD and so on, is a "manager" object always a bad idea?

I write applications for various platforms, but chiefly OS X and Windows. On both, I've been influenced by recent trends in test-driven development (TDD), SOLID, and so on. Most of this I've found to be great advice. I've found that if I have excellent test coverage, I'm more likely to refactor as needed, because I'm more confident that ...

WCF serviceType as a singleton instance

I've created a Windows Communication Foundation service (the appDomain in this case is a Windows Forms application) that initializes its serviceType class as a singleton: Starting the service works. Making a call from a client works. But if the service makes a call to itself with the above code ("//Make the 1st call to the service?"),...

C# Singleton with constructor that accepts parameters

I want to create a static class or singleton class that accepts a reference to another object in its constructor. Static classes are out, but I figured I could create a singleton that accepts parameters in its constructor. So far I haven't had any luck figuring out or googling the syntax. Is this possible? if so, how do I do it? Sorry ...

Instantiate singleton object using Class.forName()?

I want to instantiate one instance of a class from the string name of the class. ( using Class.forName().newInstance(). ) Here's the problem: I want that instance to be a singleton.. I could do this using a singleton pattern, except that newInstance calls the default constructor for a class, and with a singleton, that constructor must ...

Redeploy a singleton with timer task

I have a web server application runing with JVM, where i manage the class loader. My application have an singleton with a cycle timertask. During the redeployment i clean all the references to Class(es). I look like that my singleton with the timerTask doen't die. I add a finalize method with print. the finalize method was never call. An...

Static Constructor & Singleton class

I have an object cache which implements the Singleton design pattern. My approach to singleton was always to lazy load the static instance when the property is first accessed. public static Widget Instance { get { if(instance==null) instance = new Widget(); return instance; } } However, I know that this ap...

when to use a Singleton?

Possible Duplicate: Singleton: How should it be used Hi all, I am new to .net and in programming too. I want to that what is the real time scenario when one should use singleton design pattern. Thanks in advance, Anant ...

I want to add a singleton method with a closure to a Ruby object (Ruby)

I wish to add a singleton method to a particular object. I wish that when a instance method on a object is first called, it does some work, and then creates a singleton method for said object of the same name (that contains the work). On all subsequent calls on said object, the singleton method would shadow the instance method and would ...

Loading a Singleton's state from NSKeyedArchiver

I have a class that I've made into a singleton and am able to save it's state using an NSKeyedArchiver, but I can't wrap my head around pulling it's state back out. In the function that does the loading I have Venue *venue = [Venue sharedVenue]; NSData *data = [[NSMutableData alloc] initWithContentsOfFile:[self dataFilePath]]; NSKeyedU...

Are there penalties for Enum Singletons?

Are there (performance) penalties* associated with the Enum Singleton Pattern in any way, as it seems to be used less than the classical singleton pattern or the inner holder class idiom? * Penalties, such as the cost of serializability in cases when it is not needed and such, or is the usage low because few of the developers read Effe...

How can I make an instance of my singleton const?

Hello, I'm trying to make a wrapper for Ogre (an open source 3D engine) 's standard logging class. I want it to have the same syntax as std::cerr, and also output to cerr when running on Linux. Here's what I have: #ifndef _LOGGER_H_ #define _LOGGER_H_ #ifndef _XSTRING_ #include <xstring> #endif #ifndef __LogManager_H__ #inclu...

Can not access the Instance Data of a Singleton class from MBean

I am working against the deadline and i am sweating now. From past few days i have been working on a problem and now its the time to shout out. I have an application (let's call it "APP") and i have a "PerformanceStatistics" MBean written for APP. I also have a Singleton Data class (let's call it "SDATA") which provides some data for th...

Singleton Per Call Context (Web Request) in Unity

Hi, A few days ago I had this issue with ASP.Net threading. I wanted to have a singleton object per web request. I actually need this for my unit of work. I wanted to instantiate a unit of work per web request so that identity map is valid through out the request. This way I could use an IoC to inject my own IUnitOfWork to my repository...

Design decision: class implementing multiple patterns or other method?

I want to create a "singleton-factory class" to retrieve my specialized objects. It is possible to create such a class and does it give me some performance surplus over a simpler solution like a static factory? Or are there any other solutions? This class would be a key component of a data intensive application dealing with constant dat...