[Zope3-dev] ObjectHub Event names proposal

Gary Poster gary@modernsongs.com
06 Aug 2002 13:53:54 -0400


On Tue, 2002-08-06 at 08:06, Max M wrote:
> Sorry for jumping into the discussion with no reasonable background 
> knowledge. But will these events have those names? And is it something 
> that needs to be written in code?
> 
> If so they contain way to much information about types.
> 
> What I am afraid of that it will have the effect of::
> 
>    event = SomeEventGenerator()
>    if event.IObjectRegisteredHubEvent:
>       doStuff()
> 
> Instead of ::
> 
>    event = SomeEventGenerator()
>    if event.registered:
>       doStuff()
> 
> I am probably way of here, but I have seen stuff like that to many times 
> so just wanted to put a cautious finger in the air.

Hi Max M.  You raise a good point, but I think we need to stick with
what we have.

These names Godefroid listed are interface names, so the conditional you
would write is something more like 
  if IObjectRegisteredHubEvent.isImplementedBy(event): doStuff()
or
  if IObjectAddedHubEvent.isImplementedBy(event): doStuff()
On the face of it, then, I'd say it's even worse than you feared.

However, we need to be explicit.  There are events implementing
IObjectAddedEvent as well, for instance--that is, a non-ObjectHub
version of an ObjectAdded.  Also, services might need their own
variation to this event, IServiceAddedEvent.  We can use subclassing to
organize these intelligently, but the naming convention should also make
following along in the code reasonably clear for us humans.

I'll mention one bright side, though, in closing.  The type of code
we're talking about here will usually be in the "notify" method of an
object that has registered itself as a subscriber *for a certain event
type* (see Zope.Event.ISubscribable.subscribe, for part of this), so
conditional checking of this sort may not be regularly necessary in your
own code.  It might only be subscribed for the particular event type it
cares about anyway!

Gary