Added singleton pattern with overriding __new__ method.#109
Added singleton pattern with overriding __new__ method.#109alpiii wants to merge 1 commit intofaif:masterfrom
Conversation
|
Hi, Thanks for your pull request but we have avoided including Singleton in this repository intentionally, for different reasons. In Python you can either use the Borg pattern or just a module to achieve the same effect, so what's the benefit of using Singleton? |
|
Hi, I know Borg and liked your implementation. The code that i shared is also a singleton implementation but from a different approach and this approach might be more useful for someone else. Singleton can be really useful in different cases like configuration (if you don't use separated configuration files) or single instanced manager classes, avoiding global variables (saves from the bad effects of global variables) etc. You said you avoided to include Singleton but Borg works the same way imho. Is there any difference that i don't see? Both of them work same but have different approaches for implementation. |
|
Hi, The basic difference between Borg and Singleton is that Borg focuses on common state instead of common identity (I don't find common identity very useful). What's the advantage of using Singleton instead of Borg? Actually Borgs, Singletons, and modules have all the same problematic effect of being global and shared (instead of avoiding global state as you said). I just don't see the point of including Singleton since modules are builtin and Borg solves the same problem using a class approach (like Singleton). |
|
It is your decision to add Singleton to this repository or not. As you said, Borg does all the things that Singleton can do. Singleton might have nothing more. I just wanted to add a Singleton implementation from a different approach (overriding new) and maybe this approach might be more useful for someone else. |
No description provided.