singleton

Why does Ruby module inclusion exclude the module's singleton class?

When classes are inherited in Ruby the singleton classes are also inherited: class A def self.hello puts "hello" end end class B < A end B.hello #=> "hello" Yet with modules, this is not the case: module M def self.goodbye puts "goodbye" end end class A include M end A.goodbye #=> NameError To get around this ...

Singletons destructors

Hello, I'm using boost's singletons (boost::serialization::singleton). I have to control the queue of class destructings. One singleton consist of the object whicn uses object from second singleton. And I have to delete second singleton, before the first one. Can I do this? p.s. please, don't say anything about singleton programming tec...

C# - is it possible to implement the singleton pattern by using an interface?

Hello, I'm currently developing an application in which I'm using a plugin system. For providing unified access to a configuration screen I added a settings class to each plugin which must implement a settings interface. Furthermore each Settings class should implement the singleton pattern as shown below: public sealed class PluginSet...

Using the singleton method to create a global object

I am trying to use the singleton method to access a global object (in this example its "username"). My question is how can I modify this so that in the DB->connect() function I could do echo $this->username; without declaring $username or changing the last 2 lines? class CI_Base { private static $instance; public function CI_B...

Would Singleton be a good design pattern for a microblogging site?

I had not done with any OO in the past in projects, as I kept it simpler (in fact using archaic mysql_query calls and my own filtering) so I wanted to start a new project, learning to use design patterns with my OO along the way. I was looking to build a microblogging site for kicks, and found the Singleton design pattern class which se...

Why is it hard to unit test singletons?

I've read cases for and against using the singleton pattern. One common case against describes the difficulties in unit testing with singletons, but I'm unclear as to why this is? If the unit test is part of the build couldn't you just reference the singleton and use it when its needed? (I'm thinking from a java perspective but I guess...

"Please wait until after injection has completed to use this object" error from Guice

We have two singleton objects (declared via in(Scopes.SINGLETON)) in Guice that each uses the other in its constructor. Guice's way to implement this is with proxies - it initializes the object at first with a proxy to the other object, and only when that object is needed it is resolved. When running this code from several threads, we g...

Dynamically load class for global access (like codeigniter does)

Here is the basics of my framework: class CPU { public function load_class($class) { include_once($class . ".php"); $this->$class = new $class; } public function load_controller($class) { include_once($class . ".php"); $class = new $class; $class->index(); } public function ...

NullPointerException in a singleton when Tomcat is shutting down

I have apache tomcat 6 installed as a service on my windows xp machine. I have a class which implements ServletContextListener and it initializes a singleton required for the correct flow of the servlets (it does so on contextInitialized). The problem I'm seeing is that when I stop the service in windows (via services.msc) and I still ha...

Is a singleton shared through a different applications?

I am wondering: if I create a singleton class with a private constructor and one static method which will return instance of this class and I put it to assembly, what will happen if I access this instance from two different applications? Do the applications will always share the same instance of the singleton? And if both of those appl...

If I am not allowed to use the Singleton pattern, what are the options?

Possible Duplicate: What's Alternative to Singleton If I am not allowed to use the Singleton pattern because it is not good OOP, what are my options? I often have a lot of stuff that needs quick access. If I use a Singleton I am told it is not good OOP, and if I reference the stuff I get a lot of classes with to much reference...

Plain old singleton or spring singleton bean ?

I have a service in my application which is a singleton. My application is being bloated with the use of spring framework. I am confused over to use the singleton service as 1: Plain Old Singleton [Access them statically when required] OR as a 2: Spring singleton bean. [Use DI to inject when required] Which approach is correct ? ...

WCF app in IIS7: Losing singleton instance

I have a WCF application , with multiple WSDL webservices, hosted in IIS7 on Windows Server 2008 64Bit. The application requires a singleton to be assigned with some configuration values once, when the first webservice method is invoked (no matter what is invoked first). Edit: The backend of the system requires the use of this singleto...

In C++, how to initialize static member of a private class declared inside a Singleton template ?

Ok, I should simply tell that I want to make a base Singleton class that I can inherit from, and the way I want to achieve that is by a template. In order to avoid memory leaks, I do not use directly a pointer to the instance, but a private class that will handle deleting the pointer. Here is my actual code (not working) : template <t...

A Singleton that is not globally accessible

I just wondered what the best way is to get rid of the globally available static getInstance() in a Singleton. I do not want my Singleton classes being accessed from every point in my program. I thought about maybe having a create() public static function that creates one object and returns it but one cannot call this method twice. But...

How to deal with Singleton along with Serialization

Consider I have a Singleton class defined as follows. public class MySingleton implements Serializable{ private static MySingleton myInstance; private MySingleton(){ } static{ myInstance =new MySingleton(); } public static MySingleton getInstance(){ return MySingleton.myInstance; } } The above definition according to...

Server control - singleton for client side.

How do I create server control that will be single instance on client side for any user controls, nested masterpages etc. Also this class should be visible by intellisense in any place where it included, so i can write javascript code in any control: Manager.getInstance().add(someObj1); in other user control: Manager.getInstance().ad...

Using Static constructors to create a singleton in C#

Hi all, I've been looking at the article on creating static constructors in c# here: http://csharpindepth.com/Articles/General/Singleton.aspx Now, one option he doesn't mention is using a simple static constructor. Is there any issue with doing something like the below? If it works, it seems simpler than his complicated solutions IMHO...

c++ singleton implementation : pimpl idiom for singletons, pros and cons

When implementing singletons in c++, I see two ways to store implementation data : (A) put all implementation data in the private section and implement class as usual (B) "pimpl idiom for singletons" : hide implementation data by placing it to the 'Impl' structure, which can be defined in the implementation file. Private section conta...

Are methods in a Singleton class thread safe?

Is Concurrent method access in singleton class thread safe? I am using Spring framework (MVC) with the default scope as Singleton. For example, if the controller of my web application is a Singleton class, are the methods declared to access Model/Business/DB classes thread safe, if accessed by multiple threads at the same time? How abo...