Singular - model declaration

151 views
Skip to first unread message

Marcin Okraszewski

unread,
May 14, 2015, 8:50:44 AM5/14/15
to google-web-tool...@googlegroups.com
Hi,
I know Singular is in a prototype state, but I’m wondering about one thing. The definition of the model is done using fields. But then the controller is using a class which is apparently generated during GWT build and is providing access via getters and setters instead of fields. 

I think it is introducing some problems, mostly due to no link between the declared model and generated model.

Firstly, you cannot use the model until GWT generates it. It is very well visible on the GWT.create presentation, where there are errors in the workspace until the compilation finishes; and there are generated sources added to project source paths. This also applies to any changes to the model, like adding a field. 

Secondly, refactoring is a problem. IDE refactor tools won’t see connection between fields in declared model and those in generated class. So, every time you change model (rename a field), you will need to manually change all usages of the corresponding access methods.

Solution
My suggestion would be that the model is declared as an interface with setters and getters. Then the GWT generates implementation of that interface and this is injected into the controller. But controllers just works with the declared model interface and knows nothing about generated objects. 

Obviously, the declared model is less readable this way (will there be properties in Java some day?), but the advantage is that there are proper references between model and its usage, so that tools can see usages properly. Also, the whole code is self-contained and error-free even without the generated classes. We could then also think of adding JsInterop annotations on it, so then we could also pass the model to JavaScript if needed.

What do you think?

Cheers,
Marcin

Guillaume Rebesche

unread,
May 15, 2015, 1:42:11 AM5/15/15
to google-web-tool...@googlegroups.com
This post probably belong to singular-contrib

As far as I can see, Singular will use Annotation processing to generate an observable model. So, generated code will be available at compile time (thus right away).

cheers,
Guillaume

Marcin Okraszewski

unread,
May 15, 2015, 3:27:32 AM5/15/15
to google-web-tool...@googlegroups.com
Thanks. I didn't know there is a separate group. I've posted it there now:

https://groups.google.com/forum/?#!topic/singular-contrib/JioCFWkhEIQ

Marcin
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "GWT Contributors" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/google-web-toolkit-contributors/R7kNsMPvlDI/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> google-web-toolkit-co...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/google-web-toolkit-contributors/9f35afd8-340b-4b64-8f40-410ffa9cdf3d%40googlegroups.com.
>
> For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages