singleton

Is there any safe way to keep member pointers to COM objects from another dll in a singleton COM object?

I recently ran into a problem with a COM object that was using a singleton class factory and had members that were pointers to other COM objects implemented in a different dll than the singleton object. These other COM objects were created by the singleton object and that was the only reference to them. Since the singleton object is ne...

Difference between static class and singleton pattern?

What real (i.e. practical) difference exist between a static class and a singleton pattern? Both can be invoked without instantiation, both provide only with one "instance" and neither of them is threadsafe. Is there any other difference? ...

Objective-C Singleton instance as a static?

In Apple's documentation for their example of a Singleton, and I do understand there's more than one way to skin a cat -- but why do they bother ensuring the instance is registered as static? Take from: http://developer.apple.com/documentation/Cocoa/Conceptual/CocoaFundamentals/CocoaObjects/chapter_3_section_10.html I'm referring to: ...

Classic Singleton implementation in OCaml

I am attempting to conceptualize the Singleton design pattern (qua Java) in OCaml and have seen ever instance allude to functors or modules, neither of which I am using in a proof of concept of GoF's work. Basically, I would like to recreate the following functionality using OCaml: public class Singleton { private static Singleton Uniq...

Apple's Singleton example

Used the MyGizmoClass example in a iPhone app where I have an object that sets and maintain db info. How do I eliminate the 'MyGizmoClass' may not respond to '+sharedManager' Warning The offending line of code is: NSString *databasePath = [[MyGizmoClass sharedManager]databasePath]; ...

Shoud I make an IUnityContainer object use a Singleton pattern?

Howdy, I am new to using Unity and IoC/DI concepts. I started with the concept by rolling my own via James Kovacs' show on dnrTV in a test. His example had the Container run as a singleton accessed through a static method in an IoC class so you could register types at a startup and resolve the type throughout your application. ...

Singleton servlet?

If I declare a singleton servlet like public static class SomeServlet extends HttpServlet {..... It gives the error indicating that modifier static not allowed here in NetBeans. Please let me know how to create a singleton servlet which allows only one client at a time to execute. Thanks in Advance, Mahes ...

How to go about serving a singleton object over the network in C#?

I am creating a card game in C# for a school project. This card game is networked. The card game's game data is stored in a singleton object as gameData. gameData holds, the player names, which player the game is waiting on, player objects. Each player has 3 List objects. Where the cards are again custom objects. Originally I was going t...

Static methods or Singletons performance-wise (Android)?

In an app with a small number of POJOs and lots of helper methods that operate on them, what's better performance-wise: to make the helper classes singletons or to make the methods static? ...

Java: Design with Singletons and generics.

I am using an interface called Predicate which is used for sifting through Collections. For example, I can define public class BlackCatPredicate implements Predicate<Cat> { public boolean evaluate( Cat c ) { return c.isBlack(); } } and then use some utility findAll( Collection<T> coll, Predicate<T> pred) method to apply th...

Pros and Cons of using Singleton Pattern in DAL

I have asked to use singleton pattern implemented DAL, but I think its difficult to pool the connections,use transactions..etc I would like to know the pros and cons and also would like to know the best way to pool the connections as there can be more than 500 concurrent users for the site I am developing. DB Server is Oracle 10g. DAL...

Registering each C/C++ source file to create a runtime list of used sources

For a debugging and logging library, I want to be able to find, at runtime, a list of all of the source files that the project has compiled and linked. I assume I'll be including some kind of header in each source file, and the preprocessor __FILE__ macro can give me a character constant for that file, so I just need to somehow "broadcas...

Avoiding Global State

Currently I'm writing an app. If I want to avoid Singletons, do I have to simply pass references of everything around? For example, I have a "main" class. Class: Main +---- Screen +---- Camera +---- Terrain +---- Vehicle +---- PhysicsWorld It contains my Camera, Terrain, and Vehicle,etc classes. Now, I have issues when I'm creating...

What would be the correct design for keeping configuration settings in c++?

Say I have ini/json to store configuration setting of my desktop application,Will it be ok to have a static object with all property loaded at startup/when ever it is required or is there any other better alternative? Since this is the very first time I am doing this ,so just wanted to know whether static object is fine or singleton pat...

Is performance a sufficient reason for having a singleton or static class?

I have class that I believe should not be a singleton or static class. It has state, albeit state that could be shared by consumers. I like to stay away from singletons when there is shared state, but the argument I'm hearing is that I will reap performance benefits from only ever having 1 instance of the object exist at any given time...

Creating a new non-singleton class based on a singleton class

Hi, Is it possible in Ruby to define a new non-singleton class based on a singleton class? I tried something like this (snip): module SomeModule extend self class Singleton;end end class NonSingleton include SomeModule end nonsingleton = NonSingleton.new But of course to you gurus it's already evident that this won't work as ...

How to implement a job that runs every hour but can also be triggered from .aspx pages?

I need a method to run every so often that does some database processing. However, I may need it to be triggerable by an admin on the site. But I don't want this method being run more than once at the same time, as this could cause issues with the way it hits the database. For example, could I... Create a singleton class that runs th...

Single instance windows forms application and how to get reference on it?

I have a Windows Forms application that allows only one instance to be running at the time. I have implemented Singleton by using Mutex. The Application must be startable from commandline (with or without parameters). Application is started and exited by script. User can not take any action on it. So, application purpose is simple "indi...

static class and singleton

Isn't a class with all static members/methods a kind of singleton design pattern? Is there any disadvantage in particular of having such classes? A detailed explanation would help. ...

What are the Dangers of using a Singleton in a multithreaded application

I'm looking at using a singleton in a multithreaded Win service for doing logging, and wanted to know what are some of the problems I might encounter. I have already set up the get instance to handle syncing with private static volatile Logging _instance; private static object _syncRoot = new object(); private Logging(){} ...