singleton ... again
roegltd at gmail.com
Thu Feb 13 02:34:05 CET 2014
On Wednesday, February 12, 2014 11:34:34 PM UTC+2, Ned Batchelder wrote:
> Not all patterns are useful. Just because it's been enshrined in the
> GoF patterns book doesn't mean that it's good for Python.
Yes, i understand up to some extend usefulness of patterns.
i did not read the GoF book. yet.
> I don't understand why you would like a class to pretend to make new
> instances, but actually lie and return the same instance over and over.
> It makes them impossible to test: your unit tests all act on the same
> object, there's no way to start over with a fresh object.
> If you only want one object, create just one, and use it everywhere.
> Ned Batchelder, http://nedbatchelder.com
Actually it is not about singleton. Let say if i would like to make set
of resources with controllable quantity and not for single class but
for let say 10 or 20 classes , so i could read config file at time of program
start and create them accordingly and only when needed.
having unified attribute names within resource classes allows to do more
more from one place, let say leaving resource recovery to background thread
via proxy methods for failed resources, or scanning of objects in resource
for timeouts or ticking clocks on them for delayed response.
if there is no unified template - then for every particular class i have to
put a list within module and count on number of objects created and then supervision and other things have to be handled separately. Though i do not
defend current approach - it is a bit hack. same can be done via inheritance
from base classes or with a bit more typing via static methods.
More information about the Python-list