singleton

Yeah.. I know.. I'm a simpleton.. So what's a Singleton?

I've tried a few times to understand what a Singleton is. Perhaps I'm just too visual.. so can anyone break it down in a simple analogy. Similar Posts: http://stackoverflow.com/questions/1637635/different-ways-to-initialize-singletons http://stackoverflow.com/questions/86582/singleton-how-should-it-be-used http://stackoverflow.com/qu...

Propagating application settings

Probably a very common question, but couldn't find suitable answer yet.. I have a (Python w/ C++ modules) application that makes heavy use of an SQLite database and its path gets supplied by user on application start-up. Every time some part of application needs access to database, I plan to acquire a new session and discard it when ...

Working with singletons in .Net Remoting

I'm having a bit of a problem with a singleton class I'm exposing via remoting. In my server I have: TcpChannel channel = new TcpChannel( Settings.Default.RemotingPort ); ChannelServices.RegisterChannel( channel, false ); RemotingConfiguration.RegisterWellKnownServiceType( typeof( RemotableObject ), "RemotableObject", WellKno...

Multiple Singleton Instances

Hi all: I am writing a library of utility classes, many of which are singletons. I have implemented them as such using inheritance: template <class T> class Singleton { public: T& getInstance() { if(m_instance == 0) { m_instance = new T; } return m_instance; } ...

Do singleton exceptions work?

A collegue of mine at work gave a presentation on static factory methods (right out of Effective Java), and then gave an example of its use for obtaining static / singleton exceptions. This set off a red flag for me. Aren't exceptions stateful? Aren't they populated by the JVM for stack trace info? What savings do you really get wi...

Activator.CreateInstance - Explain it so I can understand

So I am looking at some sample code, and I am not sure what to make of this: Private Shared _instance As PollsProvider = Nothing Public Shared ReadOnly Property Instance() As PollsProvider Get If IsNothing(_instance) Then _instance = CType(Activator.CreateInstance( _ Type...

Undefined reference? Is there something I'm not seeing? (c++, singleton class)

I can't seem to make this undefined reference go away. http://imgur.com/1qqDi.png (screenshot of issue) I have this code under the private section of Scene.h: static Scene * scene_; There is a #include "Scene.h" at the very first part of the header of Scene.cpp This is the only error I'm receiving at the moment, any ideas? I'll s...

proper usage of synchronized singleton?

So I am thinking about building a hobby project, one off kind of thing, just to brush up on my programming/design. It's basically a multi threaded web spider, updating the same data structure object->int. So it is definitely overkill to use a database for this, and the only thing I could think of is a thread-safe singleton used to con...

TDD-friendly Singleton-like class

I have repository class that is used by at least 2 other classes. This repository class needs to be initialized - which is high in cost (querying database). Now, I create separate instances of repository wherever I need it. The thing is, that everytime I create repository it has to be initialized. How to design such repository to be TDD-...

Should I create a WCF connection once for my whole app, or for once for each page?

I'm working on an application that uses WPF and WCF. As it stands now, for each WPF page, a WCF connection is created for that page to use. Is this good practice? Or should I create a Singleton object to contain a WCF connection that's passed around to my pages as needed? Thanks! ...

Global variables as aliases for singletons?

Hi! I'm developing a Cocoa (Touch) app and there's certain data (like own device information and a list of locations) that I have to persist between different views and controllers. I thought of storing it as instance variables in my App Delegate, but addressing the delegate is quite cumbersome (no joy typing [[[UIApplication sharedAp...

Unique base class instance

Hi all, i'm developing a c++ dll that containts three classes: say base class Base, Derived1 and Derived2 class. The scenario: class Base { //ctor, dtor, members and methods here } class Derived1 : public Base { //ctor, dtor, members and methods here } class Derived2 : public Base { //ctor, dtor, members and methods here } T...

extending a Singleton class?

Is there a way to make like a template singleton class so that when you extend it, the extended class is also a singleton class, so I can quickly make a new singleton class just my extending the template singleton class? I am using ActionScript 3.0 if it matters. Thanks. ...

Is this a good use of the Singleton pattern?

I make a lot of "design your own ____" applications. What I do is I make a singleton class to hold all the customizations the user has chosen. For example: When you select you want something green, it updates a getter/setter in the singleton to be green. Then when the application needs to know what color was selected it gets the info fro...

How To: Auto Instantiate Singleton in C#

I want to have a Singleton that will be auto instantiated on program start. What I mean by "auto instantiated" is that the code in the Singleton should instantiate itself on program start without any calls or declarations by other code. So I want something like the following to instantiate and write out "MySingleton Instantiated" on pr...

Singleton, Logging and Global Settings - Good or Bad implementation?

I've got a logging class which requires need to be called from almost everywhere in the application. However it requires setup in the beginning of the application with "which path to write", "log level" and if it's "enabled" or not. I don't want to give this parameters every time or pass Logging class as parameter to every single objec...

WCF: Service that only allows a single client and rejects others

I need to create a WCF service that only allows a single client at a time. All other requests should be rejected, and the client must retry again later. The service will take around a minute to complete the request. I've tried: [ServiceBehavior(IncludeExceptionDetailInFaults=true, InstanceContextMode=InstanceContextM...

How to create a Singleton in C ?

Hello, I want to create a singleton in C. What's the best way? A concurrent solution would be nice.. Edit - I am aware that C isn't the first langague you would use for a Singleton, If it was the question was much simpler. ...

ASP.net MVC: Where to keep application data?

I am just starting porting an application to ASP.net MVC and I have an object holding application state (it keeps track of certain processes running on the machine, starting and stopping as necessary and sending/receiving MSMQ message). Where should I keep this object? In my current application (based on HttpListener) it is a singleton...

Do I actually have a need for a Singleton?

I'm working on a Firefox extension where I'll want to keep multiple windows in sync with the same information. The toolbar queries a remote server for info periodically, based on when the window was opened. Because Firefox windows are all separately self-contained environments, each with their own toolbar running separate code I thought ...