Derek Richardson wrote:
*Using* an int id utility, though, doesn't seem to cleanly solve the problem,


which makes me wonder if I'm understanding you. If you mean use the intid utility to map keyrefs to int ids and then map int ids to uuids, this has a few problems.

Which ones?

What I want to vary is the implementation - I want to keep the same interface.

Your UUID utility should be able to keep the same interface. But instead of doing a keyref -> UUID mapping, it refers to the intid utility for keyref -> intid and itself only does intid -> UUID. This would be completely transparent to the outsider.

This would be keeping, and adding another layer to, the implementation and I'll still have to re-implement the interface on top of it. That's more work than just copying and doesn't reduce the copying at all, as I see it. Plus, it'll be (perhaps marginally) slower.

Perhaps. That's something to profile.

If you mean use the intid utility by instantiating one and then changing the data structures and _generateId() and the events at runtime, this would indeed solve the need to copy and paste. However, this seems like an obfuscating solution - who would guess that what is masquerading as an intid utility is really a uuid utility? Perhaps that's my static-typing background speaking, but it seems cleaner to have an "abstract" id utility and then write 10 lines of code to subclass and turn it into an int id utility and then another 10 lines for uuids.

I sense that I'm missing the point here. Perhaps you can elaborate on what you mean when you say "use" and "collaboration." I usually know what those terms mean, but I'm not sure I am getting it in this context.

The paragraph definitely seems to miss the point, so let me speak code::

  class UUIDUtility(Contained, Persistent):

      def __init__(self):
          self.uuids = IOBTree.IOBTree()
          self.intids = OIBTree.OIBTree()

      def getObject(self, uuid):
          intid = self.intids[uuid]
          return getUtility(IIntIds).getObject(intid)

      def getUUID(self, object):
          intid = getUtility(IIntIds).getId(object)
          return self.uuids[intid]

I'm omitting several seatbelts and various functions to add/remove objects from the UUID utility, but I hope you'll get the idea.

-- -- Professional Zope documentation and training

Zope3-users mailing list

Reply via email to