singleton

Singleton Destructors

Should Singleton objects that don't use instance/reference counters be considered memory leaks in C++? Without a counter that calls for explicit deletion of the singleton instance when the count is zero, how does the object get deleted? Is it cleaned up by the OS when the application is terminated? What if that Singleton had allocated...

Abstracting IoC Container Behind a Singleton - Doing it wrong?

Generally, I like to keep an application completely ignorant of the IoC container. However I have ran into problems where I needed to access it. To abstract away the pain I use a basic Singleton. Before you run for the hills or pull out the shotgun, let me go over my solution. Basically, the IoC singleton does absolutly nothing, it s...

Global instance of a class in C++

As the title says. How would I create an instance of a class that is globally available(for example I have a functor for printing and i want to have a single global instance of this(though the possibility of creating more)). ...

Singleton vs Cache ASP.NET

I have created a Registry class in .NET which is a singleton. Apparently this singleton behaves as if it were kept in the Cache (the singleton object is available to each session). Is this a good practice of should I add this Singleton to the Cache? + do I need to wacth out for concurrency problems with the GetInstance() function? names...

Passing data to .NET C# WPF applications/DLLs

Hello! I have a .NET C# WPF application that I am trying to make into a single-instance application using a Mutex. This .NET application is called by a C++-based DLL using CreateProcessAsUser() and is given parameters via environment variables. Subsequent instances will also be created by the C++ DLL in the same way. Subsequent ins...

DDD repositories as singletons?

Quick question: Would it be a good or a bad idea to implement my domain-driven design style repositories as singletons? Why? Or should I maybe use a dependency injector container to manage my repositories and decide if they are singletons or not? I'm still reading DDD Quickly, and would like to see some good repository examples. ...

Singleton heritage

The singleton is explained here: http://en.wikipedia.org/wiki/Singleton_pattern#PHP_5. I want to use the singleton class as a superclass, and extend it in other classes that are supposed to be singletons. The problem is, the superclass makes an instance of itself, not the subclass. Any idea how I can make the Superclass create an instanc...

Singleton vs Static Class for exposing data read from xml

Hi, We have a PageRoles xml file which contains the page path and the user role that can access that page. We are maintaining a Dictionary in a static class, which gets loaded int static constructor for the class. The class has a method CheckIfRoleAllowed that takes in a page path and returns a bool. Each page call the CheckIfRoleAllo...

Symbian S60 - Multiple connections with a single connection dialog

Hi all, My application needs up to 3 simultaneous download connections. I am currently using a (slightly altered) CWebClient class provided in the Carbide UI framework, however using multiple instances of this for each connection prompts me multiple types to "select access point" An RSocketServ and an RConnection object exist in the cl...

Static classes in c#

In answering this question (http://stackoverflow.com/questions/352317/c-coding-question#352327), it got me wondering... Is there any danger in regarding a static class as being equivalent to a non-static class instatiation that implements the singleton pattern? ...

Singleton shared data source in Objective-C

Hey folks - I'm writing a pretty simple iPhone application. The data comes from a plist file (NSDictionary basically), that I'm trying to load into a singleton class and use across my various view controllers to access the data. Here's the implementation for my singleton (heavily modeled after this thread) @implementation SearchData ...

What's the best to way to manage a singleton?

I am messing around with different PHP logging frameworks. I am currently trying PEAR::Log. I figured that I would use its singleton function to make sure there was only one instance of the class around. I have a small daemon-like script I wanted to add logging to because it was probably the simplest script in the system to test. Thi...

ok , global variable is condemned, singleton is despised, what's the alternative?

For desktop application that is. This is just a general question that maybe only need general answers. ...

Singleton for Application Configuration

Hi In all my projects till now, I use to use singleton pattern to access Application configuration throughout the application. Lately I see lot of articles taking about not to use singleton pattern , because this pattern does not promote of testability also it hides the Component dependency. My question is what is the best way to store...

How can I animate a static object in a WPF storyboard

I have a WPF program to which I need to add a "Demo mode". Since I want my designers to be able to modify the demo mode without me having to recompile the program each time, I tough it would be a great idea to use a storyboard from an external XAML file. The "Demo mode" is basically a storyboard animating some of the application's depend...

A generic singleton

What do you guys think about this for a generic singleton? using System; using System.Reflection; // Use like this /* public class Highlander : Singleton<Highlander> { private Highlander() { Console.WriteLine("There can be only one..."); } } */ public class Singleton<T> where T : class { private static T instan...

Python: single instance of program

So, is there a Pythonic way to have only one instance of program running? The only reasonable solution I've come up with is trying to run it as a server on some port, then second program trying to bind to same port - fails. But it's not really a great idea, maybe there's something more lightweight than this? (Take into consideration...

How do you choose between a singleton and an unnamed class?

I'd use a singleton like this: Singleton* single = Singleton::instance(); single->do_it(); I'd use an unnamed class like this: single.do_it(); I feel as if the Singleton pattern has no advantage over the unnamed class other than having readable error messages. Using singletons is clumsier than using an unnamed class object: First...

How to implement a singleton model

I have a site in rails and want to have site-wide settings. One part of my app can notify the admin by SMS if a specific event happens. This is an example of a feature that I want configurable via the site-wide settings. So I was thinking I should have a Setting model or something. It needs to be a model because I want to be able to has...

"Brokered definition set" design pattern -- well-known under another name?

In a project that I've been involved with for many years, I've gradually evolved a design pattern that's proven to be extremely useful for me. I sometimes feel I should get a bit evangelical with it, but I'd be a bit embarrassed if I tried and found out that it was just my version of somebody's old hat. I've dug through Design Patterns...