Philipp von Weitershausen wrote:
Derek Richardson wrote:
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):
self.uuids = IOBTree.IOBTree()
self.intids = OIBTree.OIBTree()
def getObject(self, uuid):
intid = self.intids[uuid]
def getUUID(self, object):
intid = getUtility(IIntIds).getId(object)
I'm omitting several seatbelts and various functions to add/remove
objects from the UUID utility, but I hope you'll get the idea.
With the composition approach, the actual utility class may be a little
shorter than simply copying the whole thing, but I'll still have to copy
and just change the names on a bunch of stuff in interfaces.py (IIntIds
-> IUUIDs, IIntIdsQuery -> UUIDSQuery, etc). And I'll have to copy most
of the tests.
It still seems to me that the best approach is:
class BaseIdUtility(Contained, Persistent):
def getObject(self, id):
def getId(self, object):
... # 9 lines of code
... # registration functions and the like
implements(IIntIds) # marker
self.ids = OIBTree.OIBTree()
self.refs = IOBTree.IOBTree()
self.added_event = IntIdAddedEvent
self.removed_event = IntIdRemovedEvent
"""Generates a unique integer id.
... # this is 8 lines of code
implements(IUUIDs) # marker
self.ids = OOBTree.OOBTree()
self.refs = OOBTree.OOBTree()
self.added_event = UUIDAddedEvent
self.removed_event = UUIDRemovedEvent
"""Generates a RFC 4122 uuid.
The subclasses are pretty much complete as written here and the
BaseIdUtility is just a minor abridgment of IntIds. This allows all the
interfaces (other than the two empty markers and the events) to be
reused between intids and UUIDs and most of the tests can be performed
for both, as well.
We've talked a lot about the composition alternative to my idea, but we
haven't talked about my idea much. What is suboptimal with the way I'm
proposing, other than that it requires changing zope core? Or is that a
good enough reason to not do it?
Zope3-users mailing list