[Zope3-dev] Re: Services interfaces should not include mutators

Steve Alexander steve@cat-box.net
Sun, 22 Dec 2002 16:16:05 +0000


> This discussion provides yet more evidence for the rule of thumb that
> service APIs should not contain mutators.
> 
> In any case, I suggest a different factoring:
> 
> - Define an event notification service that just supports event 
> notification.
> 
> - Define a global event subscription service.

This can be defined by an interface, but it needn't be defined as a 
serviceType. It would be used only via zcml, or from filesystem python code.

See IGlobalAdapterService in 
lib/python/Zope/ComponentArchitecture/GlobalAdapterService.py.


> - Define a local event subscription service.
> 
> Typically, components that provide the event notification service
> will provide either the global event subscription service or the local
> event subscription service.


Ok. So, how about the following three interfaces and two serviceTypes?

class IEventPublisher(Interface):

     def publish(event):
         """Publish this event to subscribers.

         Events will often be propagated to higher level
         IEventPublishers;
         This is a policy decision for the IEventPublisher.
         """

class IGlobalSubscribable(Interface):

     def globalSubscribe(subscriber, event_type=IEvent, filter=None):
         """Add subscriber to the list of subscribers for the channel.

         subscriber must implement ISubscriber.
         """

class ILocalSubscribable(Interface):

     def subscribe(path_or_object, event_type=IEvent, filter=None):
         """Add subscriber to the list of subscribers for the channel.

         subscriber must implement ISubscriber.
         """

     def subscribeHubId(hubid_or_object, event_type=IEvent, filter=None):
         """Add subscriber to the list of subscribers for the channel.

         subscriber must implement ISubscriber.
         """

     def listSubscriptions(path_or_object_or_hubid=None,
                           event_type=None):
         """List the subscriptions, filtered by subscriber and/or
         event_type."""


<serviceType id="Events" interface="IEventPublisher" />
<serviceType id="Subscription" interface="ILocalSubscribable" />


Vastly more components are interested in sending events than in 
subscribing to receive them. Hence the short 'Events' and the longer 
'Subscription'.

--
Steve Alexander