|
|
|
Re: Extending the generated model [message #673850 is a reply to message #673714] |
Tue, 24 May 2011 23:29 |
Henrik Lindberg Messages: 2509 Registered: July 2009 |
Senior Member |
|
|
You solve this by not generating the model and instead use an external
model. You can start by making a copy of the generated model to a
separate project as a starting point.
I can however recommend to keep the model anemic and do as much
processing as possible outside of the actual model. It is simply much
easier to adapt, maintain and test. I started adding quite a few methods
to the semantic objects in my first xtext project and had to refactor
them (that was painful).
By use of guice injection and good naming it is easy to make the code
readable (as well as testable/maintainable) - say something like:
@Inject
FormsByKindFilter formsByKindFilter;
formsByKindFilter.filter(model, kind)
Then combine that with polymorphic dispatching and google collections
(iterators, filters and functions).
Just my 2c.
Regards
- henrik
On 5/24/11 4:27 PM, Vlad Dumitrescu wrote:
> Hi,
>
> I don't find anything concrete about this question, please someone point
> me out in the right direction.
>
> How can I extend the model generated from the grammar, for example to
> add more operations to classes?
> One example is that at the top level I have different kinds of Forms, in
> no particular order. I want to be able to say model.getFormsOfKind(kind)
> and get a filtered list. This is more readable than
> Util.filterFormsByKind(model.getForms(), kind) or similar approaches.
>
> Thanks in advance!
> best regards,
> Vlad
>
|
|
|
|
Powered by
FUDForum. Page generated in 0.02913 seconds