[Zope3-dev] service names

Steve Alexander steve@cat-box.net
Sun, 26 Jan 2003 13:39:42 +0200


sean.bowman@acm.org wrote:
> hello,
> 
> In all the code I've seen in Z3, the second argument to getService is a
> string literal.  This smells bad to me -- it seems to violate Once And
> Only Once.  Would it be a good idea to use a constant instead of a string
> literal?  For example::
> 
>   getService(context, defaultHubIdsName)

Why not just HubIds ?

   HubIds = 'HubIds'
   getService(context, HubIds)


> instead of::
> 
>   getService(context, "HubIds")
> 
> I am somewhat ambivalent about this since it's still possible to misspell
> 'defaultHubIdsName' and it's longer.

An alternative would be to use an interface to represent service-types.

This should be a marker interface specifically for use as a service 
identifier. For example:

   class IFoo(Interface):
       'Interface to do Foo things'

       def bar():
           'Do something bar-like'

   class IFooService(IFoo):
       'Service to do Foo things'

       # note, no methods or attributes


So, it would still be possible to have more than one service with the 
same interface.

   class IFooBazService(IFoo):
       'Service to do Foo things bazly'


--
Steve Alexander