[Zope-dev] Constant values defined in interfaces

Chris Rossi chris at archimedeanco.com
Sat Apr 4 13:19:29 EDT 2009


On Fri, Apr 3, 2009 at 7:21 PM, Wichert Akkerman <wichert at wiggy.net> wrote:

> Previously Chris Rossi wrote:
> > I was wondering if the Zope collective had given any consideration to
> > allowing constants to be defined in interfaces.  To be clear, these are
> > constant values that make up the protocol defined by the interface.  Just
> to
> > have a concrete example, let's say we're modeling an http response:
> >
> > class IHttpResponse(Interface):
> >     """Models an HTTP 1.1 response.
> >     """
> >     status = Attribute("HTTP status code for this response.")
> >
> > It might be useful to include in our interface spec what some proper
> values
> > for status code might be and make them available to applications as
> static
> > constants on the interface class.  A naive implementer might do something
> > like this:
> >
> > class IHttpResponse(Interface):
> >     """Models an HTTP 1.1 response.
> >     """
> >     HTTP_OK = "200 Ok"
> >     HTTP_NOT_FOUND = "404 Not Found"
> >
> >     status = Attribute("HTTP status code for this response.")
>
> This looks like a poor man's enum. I'ld prefer to have a proper enum
> like thing.
>

I'm sure you can think of a lot of uses of constant values where an enum
wouldn't be appropriate.  I don't know that I'd even use an enum in this
made up example.  Some use cases might be covered by an enum, sure, but
that's not really the point here.

Thanks,
Chris
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.zope.org/pipermail/zope-dev/attachments/20090404/8f654744/attachment.html 


More information about the Zope-Dev mailing list