4 ms·
SingletonFactory is an oxymoron. Edit: oh wow, it actually exists
by glutamate 7y ago
SingletonFactory is an oxymoron.
Edit: oh wow, it actually exists
- dragonwriter 7y ago> SingletonFactory is an oxymoron. It's not, you still need to create the one instance when it is first needed. It's possibly excessive abstraction, but it's not an oxymoron.
- sidlls 7y agoI've come to believe that "excessive abstraction" is practically a synonym for "object oriented programming". It takes an incredible amount of discipline to not abstract unnecessarily in an OO shop.
- anoncake 7y agoIt's not just excessive abstraction, separating Singleton and SingletonFactory can even reduce encapsulation since you can't make the Singleton constructor private.
- reificator 7y agoYou can if it's in the same file.
- rumanator 7y agoA factory method returns instances, but there is no obligation for those instances to be created on demand or each time the function is called. Some Singleton implementations only initialize the Singleton object at first call, for example, and other implementation units the object at startup.
- jknoepfler 7y agoThat's not oxymoronic at all. You have a Factory<T> interface. Depending on T and context, it may be reasonable to provide an implementation of Factory<T> that returns a singleton, something taken from an object pool, or a new instance of an object. I haven't worked in an IoC-heavy world for awhile, but a SingletonFactory is neither silly nor an anti-pattern.