Sculptor


This page describes a port of the DDD Sample using Sculptor. It is a domain model based on the cargo example used in Eric Evans’ book.

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:

Model

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: Graphviz visualization

JUnit Tests

This sample has an extensive test suite, which illustrates how to write junit tests at different levels.

Metrics

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. Lines of code

Lines of code - per package

Lines of code - summary

JUnit tests are not included, since they are very similar. Web application is not included, since it is not implemented in this Sculptor port.

Try It

If you interested in the source code you can find it as part of Sculptor’s examples:

  1. Install Sculptor and its requisites as described in the Installation Guide.
  2. Get the source code from GitHub:

    $ git clone git://github.com/sculptor/sculptor.git
    $ cd sculptor/sculptor-examples/DDDSample
    
  3. 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.
  4. Study the .btdesign files located in src/main/resources.
  5. Study the hand written code in src/main/java and the generated code in src/generated/java.

Learn more about the capabilities of Sculptor by reading the Hello World and Advanced Tutorial

Source Code

The complete source code for this sample is available in GitHub https://github.com/sculptor/sculptor/tree/master/sculptor-examples/DDDSample.

Fork me on GitHub