Skip to content

Added singleton pattern with overriding __new__ method.#109

Closed
alpiii wants to merge 1 commit intofaif:masterfrom
alpiii:master
Closed

Added singleton pattern with overriding __new__ method.#109
alpiii wants to merge 1 commit intofaif:masterfrom
alpiii:master

Conversation

@alpiii
Copy link
Copy Markdown

@alpiii alpiii commented Jan 21, 2016

No description provided.

@faif
Copy link
Copy Markdown
Owner

faif commented Jan 21, 2016

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?

@alpiii
Copy link
Copy Markdown
Author

alpiii commented Jan 22, 2016

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.

@faif
Copy link
Copy Markdown
Owner

faif commented Jan 23, 2016

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).

@alpiii
Copy link
Copy Markdown
Author

alpiii commented Jan 23, 2016

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.

@faif faif closed this Jan 23, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants