On 01 Jul 2011, at 20:33, Matt Kennedy wrote:

> I could see some value to supporting an asZnEntity protocol. As an example, 
> say I have an API which needs to support various output formats. I could 
> build my classes to use the appropriate entity builder when responding to 
> asZnEntity so that in the server code I only need to do ZnResponse ok: 
> myresponse asZnEntity, or just ZnResponse ok: myresponse if ok: sends 
> asZnEntity.

Yes, that is indeed possible, although I am not sure if lots of asXX methods 
all over are a good idea.

The problem is that there is no really useful one to one mapping between 
Smalltalk objects and Entities. An Entity has a content type (mime type) and a 
content length (rendered byte size) and knows how to represent itself on a 
binary stream or read itself from a binary stream. 

Now, given a String or a ByteArray, it is indeed possible to quickly convert to 
an Entity (ZnEntity class>>#with: does that). But that is not enough: one has 
to indicate a useful content type (ZnEntity class>#text: and #html: are 
examples of doing this automatically). In general though, there is no way to 
hide the need to set the actual type (ZnEntity class>>#with:type:). So you need 
#asZnEntityOfType: which would add parenthesis again. 

Sven

 

Reply via email to