13.03.2009 – 11:01 by Zoltan

After we have discussed several aspects of the Grails framework in our previous blog post, it is now time to say a few words about domain modeling.
In Grails, the domain model is the skeleton of the application, as in all the other languages, but in case of Grails, there’s even more emphasis on that. Your POJOs (here POGOs) take place in the domain folder, and will immediately give the definition of the database layer: all table will be generated based on them. You have to define here the relation between classes with static mappings. Some years ago everyone (sorry for those who did not) started the design of an application with the schema, the n:m, n:1, relations, struggling for hours, spending days to achieve the optimal database model, and then one could start the domain model. If you use Grails, the story ends here because the framework takes care of defining the Hibernate mappings based on the domain class definition. So, no more manual mapping of your domain objects to the database schema - which is of course still possible if you need to work with a legacy database schema. This is a nice thing since we can really concentrate on the domain and business logic.
Whats also very useful is the ability to define constraints on the domain, right inside the class where they belong to: just define static constraints. Grails has some predefined constraints like credit card numbers, email addresses and URLs, length of fields, etc., which are the most necessary ones in an average application) but one can create custom validators as well. Our application has a slightly complex domain model and we think the validators are quite handy. Any change can be accomplished without rewriting large parts of the program.
All these convenience features have saved us a lot of time on the database definition and the dynamic finder methods have saved a lot of time in providing Create-Retrieve-Update-Delete facilities. This has proven to be essential, because as we all know, the only constant is ‘change’ - not only change in technology but mainly in requirements. Nowadays most of the complexity comes from the special requirements, complicated domains, and not from the technical side.
Our current project is a perfect example here: its concept is far more complicated than the technical issues. To handle this complexity we still need an extensive set of design practices, techniques and principles, an approach, a way of thinking like domain driven design. Also we should test our domain model with simple unit tests. Grails pushes us to this way, since at the time of the domain class creation, it also generates us a unit test for that class. As a generally accepted principle we always suggest to follow test driven development. In this project we try to follow these techniques, although we have a stronger rule that sometimes overwrites the others, called common sense…
Posted in Technology, Development | No Comments »