singleton

Trying to figure out if this code creates any benefit by using a Singleton

痞子三分冷 提交于 2019-12-10 21:14:36
问题 I'm working on a project where one of the co-developers (and previous developers) use a Singleton/Facade for just about every page of class that has a lot of method calls inside of it, but that don't actually maintain the data. For instance: public class FooFacade { private static FooFacade m_facade = null; private static DataAccessManager m_dataAccessMgr = null; public StringBuilder Status {get; set; } private FooFacade() { this.Status = new StringBuilder(); } public static FooFacade

c++, multiple instances of a dll, singleton

若如初见. 提交于 2019-12-10 19:18:00
问题 I have got a DLL in which a singleton is defined. I have got an app which can load multiple instances of this DLL. The DLL needs a singleton instance per DLL instance, otherwise it will crash. I observed that there was only one singleton instance for multiple DLL instances. Why? How can I resolved it (if possible, without refactoring the singleton into something else)? Thanks for any help. 回答1: You mentioned that you have multiple instances inside your app , which implies that they all live

Boost python export singleton

泪湿孤枕 提交于 2019-12-10 18:41:33
问题 I have a singleton (from boost::serialization): class LogManager : public boost::serialization::singleton<LogManager> { ... }; And wrapper for getting instance: inline LogManager &logManager() { return LogManager::get_mutable_instance(); } What's the right way to bind this into boost.python module? I tried: class_< LogManager, boost::serialization::singleton<LogManager> >("LogManager", no_init) ... ; As a result - a lot of ugly error text in console. What's wrong? 回答1: In addition to using

When using the singleton design pattern, do other methods need to use synchronized keyword to ensure thread safety?

感情迁移 提交于 2019-12-10 18:27:35
问题 I want to ensure that the following class is thread-safe, should I use the synchronized keyword for other methods? Or use a thread-safe data structure to store Email. What should I do? public class RecycleStation { private static volatile RecycleStation uniqueInstance; private static List<Email> recycleEmailList ; private RecycleStation() { recycleEmailList = new ArrayList<>(); } public static RecycleStation getInstance() { if (uniqueInstance == null) { synchronized (RecycleStation.class) {

How to make my singleton class extendable?

泄露秘密 提交于 2019-12-10 18:00:46
问题 We have a singleton class in one of our static libraries. It is a singleton because we want to be able to "remember" its state at all times. In essence it is a User management singleton. It has a property User *user and it has methods such as - (void)authenticateUser . We want to deliver this to a client who will want to create their own - (void)authenticateUser method. To do this I envisioned they would extend the UserManager class and just override the method. However as it is a singleton

What's the difference between design pattern and enterprise design pattern?

亡梦爱人 提交于 2019-12-10 17:47:31
问题 I want to know the difference between design pattern and enterprise design pattern e.g. some books call ActiveRecord an enterprise design pattern, while singleton is a design pattern. 回答1: It probably has the most to do with what book it came from. Singleton was first popularized in "Design Patterns" by the Gang of Four. ActiveRecord was in "Patterns of Enterprise Application Architecture", by Martin Fowler. The Gang of Four described Design Patterns as generally useful object-oriented class

Simpler Singleton Based on Jon Skeet's Singleton

£可爱£侵袭症+ 提交于 2019-12-10 17:09:51
问题 I need a singleton in my code. I read Jon Skeet's page on Singletons and selected this model (#4) based on his recommendation: public sealed class Singleton { private static readonly Singleton instance = new Singleton(); // Explicit static constructor to tell C# compiler // not to mark type as beforefieldinit static Singleton(){} private Singleton(){} public static Singleton Instance { get { return instance; } } } I then went through a few steps to modify this to fit my scenario: Step 1: I

C++ getting rid of Singletons: alternative to functors and static methods

孤街浪徒 提交于 2019-12-10 16:33:53
问题 My noble quest is to get rid of singletons and static classes. Background: I have the following structures: Cmd Frequently instantiated object, it holds a name of the command (string), and functor to the static method of any class as a pointer. It is typically created in main classes such as Input, Console, Render, etc. and refers to methods within the class that it is created in, giving a runtime verbal interface to those methods. Cmds also interpret parameters in a form of a string array,

Given an instance of a Ruby object, how do I get its metaclass?

两盒软妹~` 提交于 2019-12-10 15:59:53
问题 Normally, I might get the metaclass for a particular instance of a Ruby object with something like this: class C def metaclass class << self; self; end end end # This is this instance's metaclass. C.new.metaclass => #<Class:#<C:0x01234567>> # Successive invocations will have different metaclasses, # since they're different instances. C.new.metaclass => #<Class:#<C:0x01233...>> C.new.metaclass => #<Class:#<C:0x01232...>> C.new.metaclass => #<Class:#<C:0x01231...>> Let's say I just want to know

Autofac SingleInstance not working

孤人 提交于 2019-12-10 15:49:46
问题 I am trying to get a Singleton instance working with Autofac. I'm kind of doing a quasi-mvvm type thing with Winforms, just an experiment so don't get to hung up on that. But I am trying you have my model be a single instance with a reference in a command (ICommand here is not the WPF variety): I have the following setup of a container: var cb = new ContainerBuilder(); cb.RegisterType<CalculateCommissionCommand>().As<ICommand<TradeEntry>>().SingleInstance(); cb.RegisterType<CalculationsModel>