singleton

Abstract Singleton pattern class

独自空忆成欢 提交于 2019-12-06 12:49:45
问题 I'm trying to achieve the following goal: Using this general singleton class: abstract class Singleton { private static $instance = null; public static function self() { if(self::$instance == null) { $c = __CLASS__; self::$instance = new $c; } return self::$instance; } } I'd love to be able to create Singleton concrete class such as: class Registry extends Singleton { private function __construct() {} ... } and then use them as: Registry::self()->myAwesomePonyRelatedMethod(); But obliviously

How to define a class variable on a singleton class

倾然丶 夕夏残阳落幕 提交于 2019-12-06 12:48:12
I want to define a class variable on a singleton class. I checked this program's result: class C class << self @@val = 100 end end C.singleton_class.class_variables #=> [], I expect [:@@val] C.class_variables #=> [:@@val] I expect the scope of @@val to be the singleton class, isn't it? Would you tell me how to define a class variable on a singleton class using class << self , and the reason why this program is not correct? It is because when Ruby parser meets a class variable, the current class is resolved according to the lexical scope. Cf. http://blog.honeybadger.io/lexical-scoping-and-ruby

Google App Engine singletons (Python)

久未见 提交于 2019-12-06 12:42:52
The standard way of doing singletons in Python is class Singleton(object): _instance = None def __new__(cls, *args, **kwargs): if not cls._instance: cls._instance = super(Singleton, cls).__new__(cls, *args, **kwargs) return cls._instance However, this doesn't work on App Engine, since there are may be many servers and we would get one instance per server. So how would we do it for an app engine entity? Something like: class MySingleton(db.models): def __init__(self): all = MySingleton.all() if all.count() > 0: return all.fetch(1).get() super(MySingleton, self).__init__ (*args, **kwargs) This

Accessing the same instance of a class in another form

拜拜、爱过 提交于 2019-12-06 11:59:27
问题 I'm sure this is a simple question, but I don't have enough experience to know the answer. :) DataClass, Form1, Form2 I have a public class, DataClass , in a separate file, DataClass.vb . In DataClass I have data stored in several arrays that I need to access. I have methods in DataClass so that I can access the data. One of them is GetName . Everything works fine on Form1 . I need to access the same data in the arrays on a another form, but I am required to call a new instance of the class,

Making a program with singletons multithreaded C#

 ̄綄美尐妖づ 提交于 2019-12-06 11:55:06
I have written a program in C#. Now I finished all the functionality and it works. But only running with one thread. I'm doing a lot of calculation and sometimes loading about 300 MB or more of measurement files into the application. I now want to make the program multithreaded because the user experiance is really bad in times of intense processing or i/o operations. What is the best way to refactor the program, so that it can be made multithreaded without too much affort? I know this is stuff I should have thougth before. But I havn't. I used the singleton pattern for about 3 big and

While exporting new object via require.js: does it actually create “new” object or just returns an instance of existing

一曲冷凌霜 提交于 2019-12-06 11:50:35
问题 Let's assume I have modules A, B and C in require.js. Module A export new object. define(function() { // constructor function F() { this.prop = 'some'; } // module exports return new F(); }); Modules B and C imports instance of F() from A: define(['A'], function(f_inst) { // code }); For some reason I need F to be singleton. I have not serious understanding of how require.js works. So, this is my question: do I need to use singleton patterns for F() in this case? 回答1: AMD module define d,

Enforcing method order in a python module

浪子不回头ぞ 提交于 2019-12-06 11:41:38
问题 What is the most pythonic way to deal with a module in which methods must be called in a certain order? As an example, I have an XML configuration that must be read before doing anything else because the configuration affects behavior. The parse_config() must be called first with the config file provided. Calling other supporting methods like query_data() won't work until parse_config() has been called. I first implemented this as a singleton to ensure that a filename for the config is passed

Write to a single log file in vbscript

拈花ヽ惹草 提交于 2019-12-06 11:27:24
I have written a small sub to create log file sub WriteLogFileLine(sLogFileNameFull, sLogFileLine) logfolder = "C:\Users\TEMPPAHIR\LearnVB\Logfolder\" ScriptName1 = Replace(Wscript.ScriptName, ".vbs", "") sLogFileName = ScriptName1 & "_" & date & "_" & hour(now) & "-" & minute(now) & "-" & second(now) & "_log.txt" sLogFileNameFull = logfolder & sLogFileName dateStamp = Now() Set MyLog = objFSO.OpenTextFile(sLogFileNameFull, 8, True) MyLog.WriteLine(cstr(dateStamp) + vbTab + "-" + vbTab + sLogFileLine) MyLog.Close Set MyLog = Nothing end sub I am calling this sub multiple times in my main vb

Singleton Design

半城伤御伤魂 提交于 2019-12-06 11:09:44
I'm creating a game that uses cards. I have an AppController class with one instance in the nib. The AppController instance has an NSArray instance variable called wordList. On init, the nib's instance of AppController generates a new GameCard. Every gamecard has an array of words containing 5 words selected at random from the the list in AppController. Because the list is large, I'd like to read it into memory only once. Therefore, I want only one instance of AppController, as a singleton class. Every time a new GameCard is created from within AppController, it should access that same

How to create a @Singleton bean that implements a @WebService

天涯浪子 提交于 2019-12-06 10:48:36
EDITED: after believing this is a NetBeans 7.0 editor bug. It still compiles and is deployable. I want to convert my webservice which is @WebService;@Stateless implementation into a @Singleton bean but when I replace the @WebService with @Singleton annotation... I get the image below in my IDE Editor of course when I do something silly like having both @WebService and @Stateless and deploy in glassfish I get: severe error: Annotations processing failed for... below is a link (there are more, but I'm limited to two links now) which leds me to believe Singleton beans can be used in the manner I