Mine is merely (or a close variant thereof):
static MyClass *gInstance = NULL;
+ (MyClass *)instance
{
@synchronized(self)
{
if (gInstance == NULL)
gInstance = [[self alloc] init];
}
return(gInstance);
}
...
I'm implementing a cache in a class library that i'm using in an asp.net application.
I created my cache object as a singleton pattern with a static method to update the cache which is really just loading a member variable/property with a collection of data i need cached (got some locking logic ofcourse). I figured it was a nice way to...
Let's face it. The Singleton Pattern is highly controversial topic with hordes programmers on both sides of the fence. There are those who feel like the Singleton is nothing more then a glorified global variable, and others who swear by pattern and use it incessantly. I don't want the Singleton Controversy to lie at the heart of my qu...
I've been reading about thread-safe singleton patterns here:
http://en.wikipedia.org/wiki/Singleton_pattern#C.2B.2B_.28using_pthreads.29
And it says at the bottom that the only safe way is to use pthread_once - which isn't available on Windows.
Is that the only way of guaranteeing thread safe initialisation?
I've read this thread on ...
its out of question that a dao will not hold any state.
however, for easiest access to the class, is it better to use prototype( = new every time) or singleton?
simple object creation is cheap for dao's.. it typically only holds a sessionfactory,
accessing the object from a list of singletons may be equally expensive.
clarfication: t...
How would one create a Singleton class using PHP5 classes?
...
So I have the following:
public class Singleton
{
private Singleton(){}
public static readonly Singleton instance = new Singleton();
public string DoSomething(){ ... }
public string DoSomethingElse(){ ... }
}
Using reflection how can I invoke the DoSomething Method?
Reason I ask is because I store the method names in XM...
It seems as if I'm missing the point or misunderstanding the significance of the singleton class in Ruby. I've heard and read it in many ways—some more complicated than others—and left more confused as to what it is. Is it a class in and of itself? Is it the reason why all objects belong to "class?" The concept in play here is fuzzy. I'm...
I have had a bug recently that only manifested itself when the library was built as a release build rather than a debug build. The library is a .NET dll with a COM wrapper and I am using CoCreateInstance to create a class from the dll in an unmanaged c++ app. When I finally tracked the bug down it was caused by accessing a singleton ob...
I have a singleton that uses the "static readonly T Instance = new T();" pattern. However, I ran into a case where T is disposable, and actually needs to be disposed for unit tests. How can I modify this pattern to support a disposable singleton?
The interface I would like is something like:
var x = Foo.Instance;
var y = Foo.Instance; ...
I'm trying to track down an issue in our system and the following code worries me. The following occurs in our doPost() method in the primary servlet (names have been changed to protect the guilty):
...
if(Single.getInstance().firstTime()){
doPreperations();
}
normalResponse();
...
The singleton 'Single' looks like this:
private ...
The glorified global variable - becomes a gloried global class. Some say breaking Object Oriented Design.
Give me scenarios, other than the good old logger where it makes sense to use the singleton.
...
Is there a name meaning "not a singleton"?
...
How do I implement the singleton pattern in C#? I want to put my constants and some basic functions in it as I use those everywhere in my project. I want to have them 'Global' and not need to manually bind them every object I create.
...
Say I have a class called PermissionManager which should only exist once for my system and basically fulfills the function of managing various permissions for various actions in my application. Now I have some class in my application which needs to be able to check a certain permission in one of its methods. This class's constructor is c...
A friend of mine was recently asked in a job interview to tell the difference between a standard singleton and a mono singleton. I have never heard the term before and a simple google search does not return any meaningful results.
My friend suggested that it is an object where the constructor is public but all the members are static. T...
In our data access layer at work we have this standard implementation where the class is accessed through a singleton public property which looks something like this:
public static CustomerController Instance
{
get
{
lock(singletonLock)
{
if( _instance == null )
{
_instance = new ...
I have a COM+ data service that is configured to use object pooling with a min and max pool size of 1. So I have a singleton. In some scenarios my Object count (the number of clients that have a reference to this instance) goes beyond 1 and steadily increases.
The instance creation and the one call to its method is wrapped in a using stm...
I write a singleton c++ in the follow way:
class A {
private:
static A* m_pA;
A();
virtual ~A();
public:
static A* GetInstance();
static void FreeInstance();
void WORK1();
void WORK2();
void WORK3();
}
}
A* A::GetInstance() {
if (m_pA == NULL)
m_p...
I have an application that needs to hit the ActiveDirectory to get user permission/roles on startup of the app, and persist throughout.
I don't want to hit AD on every form to recheck the user's permissions, so I'd like the user's role and possibly other data on the logged-in user to be globally available on any form within the applica...