singleton

Javascript singleton: access outer attribute from inner function

// i = inner, o = outer, f=function, a=attribute var singleton = function() { var iF = function() { return this.oA; // returns undefined } return { oF: function() { this.oA = true; return iF(); }, oA: false }; }(); singleton.oF(); If singleton were a class (as in a class-based language), shouldn't I be able to acce...

Object oriented JavaScript help

Hi, I have the following code: var HD = function() { }; HD.Car = (function() { var _date = "09/07/2010"; return { Make: undefined, Model: undefined, showMakeAndModel: function() { document.write(this.Make + " " + this.Model + " (data co...

Is the Singleton design pattern built into any frameworks?

Using a Singleton class guarantees one instance of a class to give control to the programmer. Really useful. I was wondering if for example a Singleton Interface existed in a given framework to bypass the need to create/add one explicitly? Would be handy to decalre: public sealed class MySingleton : ISingleton //or a different class ...

C# Singleton Logging Class

I am trying to figure out the best strategy for logging on the async-IO web server I am working on. I thought the easiest way was to have a singleton class that keeps Filestreams open for the appropriate log files so I could just do something like: Util.Logger.GetInstance().LogAccess(str); Or something like that. My class looks like ...

Implement a PHP singleton: static class properties or static method variables?

So, I've always implemented a singleton like so: class Singleton { private static $_instance = null; public static function getInstance() { if (self::$_instance === null) self::$_instance = new Singleton(); return self::$_instance; } private function __construct() { } } However, it recently struck me th...

Encapsulating an expensive resource without using a Singleton

I am working on updating a legacy application that is absolutely rife with Singleton classes. A perfect example would be the SnmpConnector class: public SnmpConnector { public static IEnumerable<string> HostIpAddresses { ... } private static SnmpConnector instance; public static SnmpConnector Instance { if (instance...

Singleton example in C++/CLI?

I've looked around, I need an example for Singleton class that works across 2 or more C++/CLI files. How do you declare a singleton in C++/CLI, not C# ? How do you share that singleton across two or more C++/CLI files? I keep getting Variable redefinitions when I try to share that singleton. ...

Weblogic 10.3 managed server shared memory object(s)

We are using Oracle Weblogic 10.3 as our application server. We have multiple modules that need to access an Object (contains some HashMaps) that is common for the managed server. This object will be populated via some other process on a daily basis. We do not want to have copies of this in each application, due to the large number of...

WCF Service hosted by IIS 7 and global variables ( singletons )

In my case I am using Lucene.Net for search and would like to use single instances of IndexReader and IndexSearcher. Where should I move them from a method to be able just to instantiate once for the first query and then reuse. public static List<MyType> GetIndexMatches(string fullTextIndexPath, string keyWord ) { ...

Singleton in java

I just got to read the following code somewhere : public class SingletonObjectDemo { private static SingletonObjectDemo singletonObject; // Note that the constructor is private private SingletonObjectDemo() { // Optional Code } public static SingletonObjectDemo getSingletonObject() { if (singletonObj...

Singleton PHP - database handler

Hi, I have been reading a bit lately about the singleton pattern. When readin the technical aspects of it, it appears to be ideally suited to managing a database handler or the likes. But after reading wider resources it appears that the developer community really does not favour the pattern. I am struggling to find a better solution ...

How can we ensure that there is a single instance of a class in a clustered environment

How can we ensure that there is a single instance of a class in a clustered environment? The class is Serializable. ...

Singleton factory for managing and wrapping multiple database objects

I'm building a PHP application which has to interact with several structurally identical databases. I'd like to use a singleton factory to hand out connections to the databases and minimize the number of duplicate connections. I'd also like to wrap the database class with a few functions. It would be extremely convenient if I could do a...

Can the Javascript Module Pattern be used for singletons and also for objects that are instantiated mutliple times?

I have one page with two types of forms. I have a single form of type A at the top, and then I have 1 or more forms of type B below it. I use the Module pattern + jQuery to wire up all the events on my forms, handle validation, ajax calls, etc. Is this the preferred/valid way to define a singleton, as in Form A, and a reusable object ...

implementing singleton class for Actionscript

I know actionscript does not allowed private contstructor at any time and But if i want to write a sinlgleton class in action script So how to implement it in actionscript. Can anyone provide an sample example of a singleton pattern in actionscript? ...

Singletons in Google App Engine can get expired, or does that many that any static variable can get expired? (java)

I read that in Google App Engine there is a chance that a singleton class might die, if the application gets idled for too long (or a new application instance is created), and I have experienced this myself. But does that really mean that Any static variable in any class might get expired in the application? or how can GAE identify that...

Overriding instance variable array’s operators in Ruby and scoping

I have a test class and a box class, in the test class i have a var called boxHolder, which is an array, i want to override the << method for this array. Inside the singleton how can i access moski_call ? class Test attr_accessor :boxHolder def initialize() super self.boxHolder = Array.new class << @boxHolder def <<...

GWT: IE8 problem with composite over DockLayoutPanel, the unit EM, and the Singleton design pattern

Hi everyone, I have a "Welcome Screen" which is made by hand from the entry point. On the other side, I have Widget named Main which uses the Singleton pattern: this Widget encapsulates the application funcionality and there should be only one instance in the application. This Widget is a composite over a DockLayoutPanel, which has nor...

singleton pattern in vb

I am normally a c# programmer but am now working in VB for this one project when I use to set up a singleton class I would follow the Jon Skeet model public sealed class Singleton { static Singleton instance = null; static readonly object padlock = new object(); Singleton() { } public static Singleton Instance ...

Singleton pattern

When should we use the Singleton pattern and why? ...