Mixing Groovy Builders - No Fluff Just Stuff

Mixing Groovy Builders

Posted by: Andres Almiray on November 29, 2007

The cat is out of the bag (so to speak), Scott blogs about ObjectGraphBuilder and DomainBuilder, both are brainchildren of his. The former is already available in Groovy 1.1-rc-3, the later will see the light of day on Grails 1.0

Both of them will let you build a complex object graph provided you follow the usual conventions for beans, but the best thing IMHO is that OGB extends from FactoryBuilderSupport, thus enabling new features as "factory sharing". Suppose that you have a domain model where some classes are observable, i.e, they will fire PropertyChangeEvents whenever one of their properties changes value, and you'd like to connect listeners at the same you build the graph, that sounds like a job for bind() but that factory is available in SwingBuilder only. Should you copy the code? no need to, just register the BindFactory into your instance of OGB and your done! This is possible because SwingBuilder inherits from FBS also, take a look at the following example and see for yourself

Not only did the names of the employees were changed as the company's name was updated, but the value was also transformed, thanks to the options available on bind(). In case you were wondering, GraphicsBuilder does the same to support binding on shapes.

Keep on Groovying!
Andres Almiray

About Andres Almiray

Andres is a Java/Groovy developer and a Java Champion with more than 20 years of experience in software design and development. He has been involved in web and desktop application development since the early days of Java. Andres is a true believer in open source and has participated on popular projects like Groovy, Griffon, and DbUnit, as well as starting his own projects (Json-lib, EZMorph, GraphicsBuilder, JideBuilder). Founding member of the Griffon framework and Hackergarten community event. https://ch.linkedin.com/in/aalmiray

Why Attend the NFJS Tour?

  • » Cutting-Edge Technologies
  • » Agile Practices
  • » Peer Exchange

Current Topics:

  • Languages on the JVM: Scala, Groovy, Clojure
  • Enterprise Java
  • Core Java, Java 8
  • Agility
  • Testing: Geb, Spock, Easyb
  • REST
  • NoSQL: MongoDB, Cassandra
  • Hadoop
  • Spring 4
  • Cloud
  • Automation Tools: Gradle, Git, Jenkins, Sonar
  • HTML5, CSS3, AngularJS, jQuery, Usability
  • Mobile Apps - iPhone and Android
  • More...
Learn More »