I've been reading about Singleton pattern for last few days. The general perception is that the scenarios where it is required are quite few (if not rare) probably because it has its own set of problems such as
In a garbage collection environment it can be an issue with regards to memory management.
In a multithreaded environment it ca...
I need to call a static function from an object using the Singleton design, but using a variable as the class name.
The best way, $class::getInstance();, is only available in PHP 5.3, and the other way I found, call_user_func(array($class, 'getInstance'));, results in the maximum execution time being breached. Does anyone know why this ...
Just the other day I have seen code that uses the so called singleton pattern. Meaning something along the lines of
class MySingleton{
public:
void foo() { ... }
static MySingleton
return singleton
}
private:
MySingleton(){ ... }
~MySingleton(){ ... }
int bar;
};
I do see why one would want to do that:
...
Hi,
I'm writing an application which will run as a daemon. UIs will connect to it over TCP. Now, there is a class called UiTcpInterface which will handle all communication between the UI and this daemon.
Now, I'm faced with the problem of ensuring there is only one instance of UiTcpInterface. What would be the best way to do it? Curren...
How to avoid multiple instances of windows form in c# ?? i want only one instance of the form running. Because there are chances of opening the same form from many pages of my application.
...
I have a class (RInterfaceHL) that calls another class (JRIEngine) which provides native methods on a single-threaded application. Therefore I only want to have a single instance of my class (RInterfaceHL) per JVM.
I can use the singleton pattern with static initialization to ensure only a single instantiation of RInterfaceHL, but RInt...
I'm looking to create a singleton in Delphi. I've done this before using older versions of Delphi, and ended up using global variables (in the implementation section) and using initialization and finalization to take care of the instance. Also there was no way of preventing the user from creating an instance as you couldn't hide the stan...
Hi, i'm using DbSimple, but there is some code which i could write into another module. Here is it's code:
<?php
require_once 'config.php';
require_once 'DbSimple/Generic.php';
class MysqlWorker
{
private static $instance = NULL;
public function getInstance()
{
if( self::$instance == NULL )
{
s...
Hi, i have code:
class ConfigReader
{
private static $instance = NULL;
protected $configData = array();
public function getInstance()
{
if( self::$instance == NULL )
{
self::$instance == new ConfigReader();
}
...
I've been sitting on this idea for quite a long time and would like to hear what you guys think about it.
The standard idiom for writing a singleton is roughly as follows:
public class A {
...
private static A _instance;
public static A Instance() {
if(_instance == null) {
_instance = new A();
}
retu...
New to NHibernate(my disclaimer). I came across a similar and interesting article regarding MVC, however, I'm more curious as to what general best practices are for managing NHibernate sessions within a generic web application.
I've come across the Burrow project, but I'm starting to realize there seems to be a few different directions ...
public class MySingletonClass
{
public MySingletonClass()
{
_mySingletonObj = Instance();
}
public static MySingletonClass Instance()
{
if (_mySingletonObj == null)
{
lock (typeof(lockObject))
{
if (_mySingletonObj == null)
_mySingletonObj = new MySingletonClass();
}
}
...
Up until this point all the .NET remoting code I have written or worked with has been exposed as SingleCall.
I ran across a .NET remoting component hosted in a Windows service that is exposed as a Singleton.
This object has the potential to be called by more than one client at the same time, and it has no locks or other provisions to p...
How to create a singleton class which inherit from MarkUpExtension class?
...
Putting aside, for now, the arguments about the relative virtues and disvirtues of the Singleton pattern, and considering that a Singleton is typically considered to be an instance that persists for the lifetime of an application, what would be the best way to go about having a Singleton that has a limited life?
Is there anything amiss ...
I've inherited a project that stores various parameters either in a config file, the registry and a database. Whoever needs one of these parameters just reads (and in some cases writes) it directly from the store. This, or course, is stupid, so my first thought was to refactor the existing code so that the client doesn't know where the p...
Currently I have been very interested in this "design pattern". I am not sure though if there are downfalls using this strict global state implementation. So, when do you think not to practice singleton in an application?
...
Can anyone explain why a singleton instance of the MyCLController class is used in the sample iphone app LocateMe found here
as well as the overriding of retain, retainCount, release, and autorelease? Any help would be very much appreciated!!
...
Hi Guys
I have a very interesting situation , i have figured out that Singleton pattern is not all possible with .net framework (Any version)
look at this code below
namespace SingletonPattern
{
class Singleton
{
private static readonly Singleton instance = new Singleton();
private static int mcount = 0;
private ...
A friend of mine today asked me why should he prefer use of singleton over global static object?
The way I started it to explain was that the singleton can have state vs. static global object won't...but then I wasn't sure..because this in C++.. (I was coming from C#)
What are the advantages one over the other? (in C++)
...