[Interface-dev] Re: Some thoughts on attribute specifications in interfaces

Philipp von Weitershausen philipp at weitershausen.de
Wed Jun 16 07:47:18 EDT 2004


Jim Fulton wrote:

> When thinking about attribute specifications (e.g. schema fields)
> we should separate the modeling of the relationship from the
> specification of the value.
> 
> For example, using zope.schema, we can model an attribute:
> 
>    class IFoo(Interface):
> 
>       size = Int(description="The number of doo dads in a foo",
>                  required=False,
>                  min=0,
>                  )
> 
> This says that objects that provide IFoo have size attributes.
> The size attributes are positive integers. An alternative way to
> express this might be:
> 
>    class IFoo(Interface):
> 
>       size = Attribute(description="The number of doo dads in a foo",
>                        required=False,
>                        type=Int(min=0),
>                        )

This indeed looks much better because it makes the type constraint part 
of the attribute specification and not the other way around. I also like 
the way it makes it possible to reuse type specifications for method 
definitions.

> Note that thinking about attributes as relationships between objects
> (or specifications of objects) sheds some light on the schema binding
> issue we've been wrestling with:
> 
>   http://dev.zope.org/Zope3/NoMoreSchemaBinding
> 
> It now seems natural to me that, when applying an attribute definition
> to an attribute manipulation task, such as display, input, or
> validation, that we would take the object the attribute is on into
> account.
> 
> Consider the problem of displaying an object attribute on a form.
> Currently, we "bind" the field to the object and then get an adapter
> (view) on the bound field. I think a better way would be to get a
> three-object adapter (view) on the field value specification, the
> attribute specification, and the object that provides the schema.
> This allows us to dispatch to an adapter based on the value
> specification, which is generally most important for selecting display
> components, the attribute specification, and the object type.
> 
> For validation, we'd use subscription adapters on the value
> specifications, the field types and the object type.
> 
> These ideas are similar to those proposed in:
> http://dev.zope.org/Zope3/NoMoreSchemaBinding
> except that 3-object, rather than 2-object adapters are used.

This is an excellent solution to the schema binding problem.

> Note that we could implement this in a way that would retain backward
> compatibilities with existing schemas.

We could also take this opportunity to merge zope.schema and 
zope.interface. zope.schema would basically stick around the way it is 
providing the backward compatability. zope.interface could provide the 
new type specification as proposed here.

Philipp




More information about the Interface-dev mailing list