singleton

Singleton Referencing

Okay...I have a situation where a C# .dll is a singleton. Now, what I want to be able to do is when the singletonInstance is instantiated be able to provide a reference to any other applications that may start. So, I looked up NamedPipes and that would work - except for one thing, this must be cross-platform, or platform independent. I h...

How can the proxy pattern be used to replace a singleton?

Hi all, This is in response to some comments in what is so bad about singletons There it was suggested that the proxy pattern can be used instead of a singleton to cache DB data. But I cannot see the advantage, and in fact the singleton seems more "controllable". Let me elaborate on the problem. Assume you have a database, with a la...

Is it bad to call a singleton method many time over and over on a page in PHP?

In PHP if I create a singleton method for like 5 different caching classes (memcache, apc, session, file, cookie) Then I have a main cache class which basicly routes my set() and get() methods to the appropriate caching class. Now lets say I need to use the session, cookie, memcache, and file cache all on the same page. My main cache ...

How to maintain data across object instances in Objective-C?

I've had some experience developing for the iPhone but am entirely self taught and am trying to improve my practices. This is a question that is probably pretty introductory to programming. What is the best way (or is it possible) to maintain instance variables with values that are common to all instances of an object? Is it possible to...

Singleton issue of provider model

Hi, Is the singleton requirement of a provider is a performance hit ? Because all the database read/write opertions must be taking place through that singleton. Wouldnt it be an issue with multiple users doing read/write operation in a site like Blogger. ...

Registry or Singleton pattern in PHP?

I am working with PHP classes and objects now. In this question the names of fields and methods are made up just so you get an idea of what I am talking about. It is related to using the singleton and registry design patterns. Now lets say I need to access a Database object, Cache Object, Core Settings object, Session object in al...

Is it ok to call a Registry Pattern object inside of the objects that make up the Registry?

I have asked a few question lately about the use of the singleton and registry patterns but here is a new question I have. Let's say I have 3 main class object in PHP that I need to have access to inside 20 other class files and sitewide. Database object Cache object Core object I then can use a Registry pattern to store all...

Ruby access magic

Assume, I have the following class: class MyClass attr_accessor :vars def initialize @vars = [] end def add_var var @vars << var end end I want to access inners vars like this: x = MyClass.new('root') x.add_var 'test' x.add_var 'something' x.add_var Myclass.new('google') x.google.add_var 'nice' puts x.test puts ...

Singleton class in java

Just i was thinking about the other ways of writing singleton class. So is this class considered as a singleton class? public class MyClass{ static Myclass myclass; static { myclass = new MyClass();} private MyClass(){} public static MyClass getInstance() { ...

Is implementing a singleton using an auto-property a good idea?

I recently found out about auto-properties and like them quite a lot. At this moment I am trying to use them everywhere where I can. Not really to just be able to use them everywhere, but more to see how well they work in most situations. Now I am making a singleton and thought:"Hey, let's try auto-properties here as well". public cla...

singleton patterns VS static types

Possible Duplicate: Advantage of Static class over use of Singleton Usually, everytime I needed a single systemwide object I used the singleton pattern. M question is, why shouldn't i just implement the object as static and get the single object behaviour naturally ? Are there any cons to use static types over singleton factore...

Pylons: free module-level variables?

Not even sure if module-level is correct here, but... I have a Pylons project and within the model component I have a global variable, doc, in __init__.py that I want to use from different Query objects. (doc is a Document handle on an XML file that I am using as a fake DB.) My question is, when does __init__.py's scope end? Currently I...

Cannot access private member in singleton class destructor

Hello, I'm trying to implement this singleton class. But I encountered this error: 'Singleton::~Singleton': cannot access private member declared in class 'Singleton' This is flagged in the header file, the last line which contains the closing brace. Can somebody help me explain what is causing this problem? Below is my source code. ...

ASP .NET Singleton

Hello, Just want to make sure I am not assuming something foolish here, when implementing the singleton pattern in an ASP .Net web application the static variable scope is only for the current user session, right? If a second user is accessing the site it is a different memory scope...? Thanks ...

How to implement a singleton pattern with an infinite loop - C#

I am currently working on an application in C# that runs on an infinite loop with a Thread.Sleep call after each iteration of the other method calls. My main is - static void Main(string[] args) { bool isOnlyInstance = false; Mutex mutex = new Mutex(true, "RiskMetricsSensitivitiesDatabaseLoader", out isOnlyInstance...

Tracking the process of a singleton process in a web application

When I hit the run button (in my Default.aspx), a process starts (this process contacts a webservice to get some files, etc). How do I: Ensure that only a single process is running at a time (i.e. if I refresh the browser, I don't want to start the process a second time) Track progress - there are 4 points of the process (at 25%, 50%,...

C++: Undefined reference to instance in Singleton class

Hi, I'm currently trying to implement a factory as a singleton. I practically used the textbook example of the Singleton pattern. Here's the .h file: namespace oxygen{ class ImpFactory{ public: static boost::shared_ptr<ImpFactory> GetInstance(); private: static boost::shared_ptr<ImpFactory> mInstance; }; and here's the .cp...

What is a singleton in C#?

Pretty straight forward question. What is a Singleton and when should I use it? ...

refreshing singleton object data in object c

here is code + (SalesCollection*)sharedCollection { @synchronized(self) { if (sharedInstance == nil) { [[self alloc] init]; // assignment not done here } } return sharedInstance; } + (id)allocWithZone:(NSZone *)zone { @synchronized(self) { if (sharedInstance == nil) { sharedInstance = [super allocWithZone:z...

singleton inheritance question

how do i (and does it makes any sense?) inherit from the singleton class other classes that need the same functionality? ...