Sculptor will help you with the static structure of the application. It can generate the data part of the domain objects and boilerplate code for services and repositories. It has a nice runtime framework for especially the persistence implementations, such as standard queries. However, to qualify as a true DDD application the domain objects must have complex behavior - business logic. With this sample we illustrate how to integrate manually written logic with the automatically generated parts.
Table of Contents:
The definition of the domain model, using Sculptor’s textual DSL is separated in one file for each Module, plus one “empty” top file, which imports the other files.
The generated vizualization with GraphViz looks like this:
This sample has an extensive test suite, which illustrates how to write junit tests at different levels.
- logic in the domain objects is tested with ordinary junit tests, without any need for database emulation or spring container
- repositories and details of the persistence are tested with DBUnit tests and spring container and hibernate using in memory database
- services are tested in a similar way as the repositories, but also using easymock framework
It is interesting to compare the fully hand written original DDD Sample with this partly generated port. The number of hand written lines of code in the Sculptor port is 783. Compared to 1179 in the original. The business logic is almost identical, but the Sculptor variant has less lines of code since much of the boring boilerplate code is generated. It has bean measured with JavaNCSS.
JUnit tests are not included, since they are very similar. Web application is not included, since it is not implemented in this Sculptor port.
If you are only interested in a sneak preview of the source code you can download it here: Sculptor-DDDSample-src.zip
Another choice is to try the real thing:
- Install Sculptor and its requisites as described in the Installation Guide.
Get the source code from GitHub:
$ git clone git://github.com/sculptor/sculptor.git $ cd sculptor/sculptor-examples/DDDSample
- Build with
mvn clean install. This will also run all JUnit tests located in
src/test/java. Take a look at some of them and run them from Eclipse also.
- Study the
.btdesignfiles located in
- Study the hand written code in
src/main/javaand the generated code in
The complete source code for this sample is available in GitHub https://github.com/sculptor/sculptor/tree/master/sculptor-examples/DDDSample.