singleton

Rails - Singleton class troubles with rspec feature

跟風遠走 提交于 2021-01-29 10:32:36
问题 I have a problem testing a functionality that depends of a Singleton class. That class (ERPDao) is a suite with diferent methods that helps application to connect with external ERP vía REST services using Faraday gem. URLMaker is a helper class for build requests strings. When i try to run a feature spec that depends of one of this methods i have the following message in rspec: Failure/Error: result = ERPDao.instance.get_credit_info(erp_id) NoMethodError: undefined method `instance' for

Invalid initialization of type using class templates

只愿长相守 提交于 2021-01-29 05:32:02
问题 I have a rather complicate singleton template starting with template <class T> class Singleton { public: static T& GetInstance(){ static T instance; return instance; } private: Singleton() {} ~Singleton() = default; }; and then class Class2; template <class T> class Class1{ void sayHi(); }; using Class1Singleton= Singleton<Class1<Class2>>; So you can see I have a singleton of Class1 (that is also template based so I use Class2 for that). Then in another part of the code I have Class1Singleton

C++ is static variable initialization with = atomic?

北战南征 提交于 2021-01-29 03:59:02
问题 The Meyers Singleton depends on the fact that local static variable initialization is atomic. I'm building something similar but I want the singleton to actually be one of a number of derived types. The base class getInstance() method should call a factory that will return the appropriate type. My first idea is static Foo *instance = FooFactory(...); 8.5p2 of N3337 seems to indicate that this is strictly initialization and not initialization and assignment and I interpret that to mean the

Singleton returning multiple instances

我怕爱的太早我们不能终老 提交于 2021-01-28 07:12:50
问题 I have a singleton class that is returning multiple instances, and I can't figure out how. It is likely that there are multiple threads calling on the singleton class, but if that is the case, I'm not sure how I can make it work properly. Here's some of the code. public class SomeClass{ private static final String TAG="someClass"; private volatile static SomeClass instance = new SomeClass(); public static synchronized SomeClass getInstance() { Log.v(TAG,"Returning instance "+instance); return

extern vs Singleton class

爷,独闯天下 提交于 2021-01-27 15:52:01
问题 Say we have some external linkage using the extern keyword. I have (in class1.cpp): MyClass* myClassVar = NULL; The constructor initializes the above, and destructor deletes. Then in class2.cpp and class3.cpp there is: extern MyClass* myClassVar; These classes use myClassVar (doing the usual null checks etc). Would a Singleton be preferred? (I know globals are bad etc, and a Singleton is just syntax sugar). Is there an advantage to change the above code to the below? static Singleton&

extern vs Singleton class

倾然丶 夕夏残阳落幕 提交于 2021-01-27 15:21:23
问题 Say we have some external linkage using the extern keyword. I have (in class1.cpp): MyClass* myClassVar = NULL; The constructor initializes the above, and destructor deletes. Then in class2.cpp and class3.cpp there is: extern MyClass* myClassVar; These classes use myClassVar (doing the usual null checks etc). Would a Singleton be preferred? (I know globals are bad etc, and a Singleton is just syntax sugar). Is there an advantage to change the above code to the below? static Singleton&

Ruby: DRY class methods calling Singleton instance methods [duplicate]

时光总嘲笑我的痴心妄想 提交于 2021-01-27 08:44:55
问题 This question already has answers here : Calling a method of a Ruby Singleton without the reference of 'instance' (5 answers) Closed 5 years ago . I have the a Singleton class ExchangeRegistry which keeps all the Exchange objects. Instead of needing to call: ExchangeRegistry.instance.exchanges I want to be able to use: ExchangeRegistry.exchanges This works, but I'm not happy with the repetition: require 'singleton' # Ensure an Exchange is only created once class ExchangeRegistry include

Ruby: DRY class methods calling Singleton instance methods [duplicate]

时间秒杀一切 提交于 2021-01-27 08:44:49
问题 This question already has answers here : Calling a method of a Ruby Singleton without the reference of 'instance' (5 answers) Closed 5 years ago . I have the a Singleton class ExchangeRegistry which keeps all the Exchange objects. Instead of needing to call: ExchangeRegistry.instance.exchanges I want to be able to use: ExchangeRegistry.exchanges This works, but I'm not happy with the repetition: require 'singleton' # Ensure an Exchange is only created once class ExchangeRegistry include

Ruby: DRY class methods calling Singleton instance methods [duplicate]

ぐ巨炮叔叔 提交于 2021-01-27 08:43:34
问题 This question already has answers here : Calling a method of a Ruby Singleton without the reference of 'instance' (5 answers) Closed 5 years ago . I have the a Singleton class ExchangeRegistry which keeps all the Exchange objects. Instead of needing to call: ExchangeRegistry.instance.exchanges I want to be able to use: ExchangeRegistry.exchanges This works, but I'm not happy with the repetition: require 'singleton' # Ensure an Exchange is only created once class ExchangeRegistry include

Ruby: DRY class methods calling Singleton instance methods [duplicate]

|▌冷眼眸甩不掉的悲伤 提交于 2021-01-27 08:43:34
问题 This question already has answers here : Calling a method of a Ruby Singleton without the reference of 'instance' (5 answers) Closed 5 years ago . I have the a Singleton class ExchangeRegistry which keeps all the Exchange objects. Instead of needing to call: ExchangeRegistry.instance.exchanges I want to be able to use: ExchangeRegistry.exchanges This works, but I'm not happy with the repetition: require 'singleton' # Ensure an Exchange is only created once class ExchangeRegistry include