[Zope3-dev] Re: ObjectHub

Steve Alexander steve@cat-box.net
Sat, 07 Dec 2002 14:30:50 +0000


Gary Poster wrote:
> 
> 
> Steve Alexander wrote:
> 
>> Can you explain what you want in terms of the Requirements for the 
>> 'register' method that I posted?
>>
>> Here they are again:
>>
>> * Postcondition: the given object's location is registered
>>
>> * If the postcondition cannot be met, you get an exception
>>
>>   Otherwise...
>>
>> * You want to know the hubid of the registration
>>
>> * You want to know whether registration did any work
>>
>> I'd like to start by finding out if the requirements for this method 
>> are reasonable. Then, we can move on to think about how we spell it.
> 
> 
> Sure.  I think the first three are great.  The last one feels somewhat 
> questionable to me, but then you gave a use-case in your code, so ok, I 
> guess.  If you didn't have the last requirement, of course, you could 
> always just return the hubid:
> 
>  >>> hub.register('/foo/bar/baz')
> 23
>  >>> hub.register('/foo/bar/baz')
> 23
> 
> Is the use case you gave for requirement 4 a reasonable one?  My 
> response is, again, +0.
> I see it, but grudgingly: I want to say YAGNI.

One thing I forgot to point out is that by far the most usual use of 
'register' will be like this:

   hub.register(some_object)
   hub.register(some_other_object)

That is, the client code doesn't care about the return value at all. It 
just wants to ensure the given object is registered.


We could be explicit about this and have an 'ensureRegistered' method.

   def register(object_or_location):
       '''Register the given location.

       Returns the tuple (hubid, is_new_registration)
       '''

   def ensureRegistered(object_or_location):
       '''Ensure the given location is registered.

       Returns the hubid of the location.
       '''

But, I think that this a YAGNI.

--
Steve Alexander