[Python-Dev] Thoughts on validation, events, rules (original) (raw)
Jim Fulton jim at zope.com
Sun Aug 8 15:53:46 CEST 2004
- Previous message: [Python-Dev] Re: Python-Dev Digest, Vol 13, Issue 77
- Next message: [Python-Dev] Re: Thoughts on validation, events, rules
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
I'm a bit unsatisfied with container constraints:
http://dev.zope.org/Zope3/ContainmentConstraints
While I think this was a step forward conceptually, it has turned out to be a bit unwieldy in practice:
Container constraints are difficult to express. I've written convenience API's to make the basic machinery of expressing constraints easier, but there is a problem that's not so easy to fix. Often you want to express a symmetric constraint between two interfaces. For example, you want to say that objects implementing I1 can only contain objects implementing I2 and that objects implementing I2 can only be contained in objects implementing I1. If the constraint is expressed in the interfaces themselves, you can only express it by either defining the interfaces in a single operation or by mutating the interfaces. I don't like the idea of mutating interfaces, but perhaps I just need to get over that.
Container constraints are cumbersome to check.
Container constraints force the contained objects to implement IContained. This is fine when the contained objects will actually access their containers. Often, however, we want to constrain an object's container for external reasons. For example, we might want to only allow indexes to be added to catalogs, even though indexes are passive and never invoke operations on their containers. In this case, the constraint is not part of the index's contract.
I've been thinking of other ways to solve this problem.
In the context of schema validation, we've been thinking of using subscription adapters:
http://dev.zope.org/Zope3/NoMoreSchemaBinding
http://mail.zope.org/pipermail/zope3-dev/2004-June/011315.html
The advantage of subscription adapters is that they provide the ability to express constraints in a highly flexible and decentralized manner. Another advantage of using subscription adapters is that doing so takes advantage of a highly optimized mechanism and should be fairly efficient.
It occurred to me today that subscription adapters provide a form of rule-based processing. Any number of rules (subscribers) can fire as the result of some event, where an event could take the form of a query, such as "validate adding this object to this container" or "validate setting this attribute to this value".
It's interesting to note that validating adding an object to a container and validating assigning an attribute are both special cases of validating establishing a relationship between two objects.
Jim
-- Jim Fulton mailto:jim at zope.com Python Powered! CTO (540) 361-1714 http://www.python.org Zope Corporation http://www.zope.com http://www.zope.org
- Previous message: [Python-Dev] Re: Python-Dev Digest, Vol 13, Issue 77
- Next message: [Python-Dev] Re: Thoughts on validation, events, rules
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]