Domain-driven design (DDD) focuses on what matters in enterprise applications: the core business domain. And Naked Objects lets you build DDD applications just by writing the core domain classes, the rest of the application is taken care of for you.

This blog supplements and expands on my book, Domain Driven Design using Naked Objects, describing how you can rapidly develop and test domain applications using Naked Objects.

Using Project Lombok with Naked Objects

Old super 8 video camera's

Project Lombok is a recent project that exploits with Java 1.6’s APT (Annotation Processing Tool) API to generate boilerplate code from annotations. In this screencast I show how Lombok can be easily used to remove the boilerplate getters and setters from a pojo domain object.

At the time of writing Project Lombok is still very new.  It doesn’t need any IDE, but if you are using an IDE then only Eclipse is supported (and it’s still relatively early days).  But the project leads are also actively encouraging the community to experiment with new annotations and features (see for example the related Project Morbok). I can see several possibilities for Naked Objects though:

  • currently we use bytecode enhancement (cglib or javassist) to override the getters for lazy loading, transparently calling the DomainObjectContainer#resolve().   We do something similar in the setters to mark the object as dirty, by transparently called DomainObjectContainer#objectChanged.  An enhanced version of Lombok’s @Getters and @Setters, also applied to collections, might mean us being able to remove this bytecode enhancement
  • an enhanced version could also generate the standard supporting methods, modifyXxx() and clearXxx() method for properties, and addToXxx() and removeFromXxx() for collections.  These could then call hook methods (onModifyXxx() and so on) for any further business processing
  • going further still, these standard supporting methods be generated the standard mutual registration pattern for bidirectional dependencies.  This would need the annotation could specify whether the relationship is bidirectional, equivalent to JPA’s mappedBy or Hibernate’s “inverse” attributes.  In fact, why not simply use JPA’s annotation…?

I suspect a few other of the conventions of the Naked Objects programming model could be ported over to Lombok… if you have any good ideas, post a comment.

Post to Twitter Post to Yahoo Buzz Post to Delicious Post to Digg Post to Facebook Post to Reddit Post to StumbleUpon

5 comments to Using Project Lombok with Naked Objects

Leave a Reply

 

 

 

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>