[Zope-dev] singleton vs. utility (was Re: implementing zope.component 4.0)

Tres Seaver tseaver at palladion.com
Tue Dec 1 11:40:19 EST 2009


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Lennart Regebro wrote:
> On Tue, Dec 1, 2009 at 01:16, Gary Poster <gary.poster at gmail.com> wrote:
>> I don't love "singleton."  I think it is better than "utility."  I agree at least that it probably isn't better enough to introduce confusion.  I'd be more insistent on "singleton", or finding a better term than either of them, if this were a fresh API.
> 
> I wonder if the best isn't to make the documentation clearly say
> "Utilties are singleton components that can be looked up per
> interface".

+1 to improving the documentation.

- -1 to using the term "singleton".  The term is loaded up with things
that aren't relevant to what utilities do:  in particular, there is no
requirement / promise that the object registered as a utilitiy is an
instance of a class, much less that its class / module jumps through
hoops to guarantee that only one instance can exist[1].  The promise is
merely that the object returned from the lookup will provide the given
interface:  no more, no less.

I have often registered functions as utilities, for instance, where the
contract of the corresponding interface was just that it be callable
with a given signature.  I even recall registering a module as a
utility, although I can't find the example at the moment.

"Global objects" is a more accurate description of the things registered
as utilities from ZCML / imperative code:  even that term is inaccurate
once persistent objects get registered.


[1] See the description of the Singleton pattern in the
    mother-of-all-wikis: http://www.c2.com/cgi/wiki?SingletonPattern




Tres.
- --
===================================================================
Tres Seaver          +1 540-429-0999          tseaver at palladion.com
Palladion Software   "Excellence by Design"    http://palladion.com
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAksVRvMACgkQ+gerLs4ltQ79/gCfbUH7gsgJT6yER0U/zBUxrT0E
qzQAoKYOe6OnLRXs4bveRXST8Ogkxwj6
=eh4i
-----END PGP SIGNATURE-----



More information about the Zope-Dev mailing list