Two Laptop Bag
The moose likes Groovy and the fly likes Modular Closures for Builders (FactoryBuilderSupport) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Languages » Groovy
Bookmark "Modular Closures for Builders (FactoryBuilderSupport)" Watch "Modular Closures for Builders (FactoryBuilderSupport)" New topic

Modular Closures for Builders (FactoryBuilderSupport)

John Dee

Joined: May 13, 2010
Posts: 3
The following is an attempt to modularize my DSL files because
there is a nested closure that is identically defined in
many of these DSL files.

Current (working) Non-Modular Implementation



The above works, but the problem is that the entire closure drug(){...}
is used in many other DSL files.

So, what I would like to do is pull the drug(){...} closure out of patient.groovy and put it
into a new drugs.groovy. The following is what I modified the above to in order to modularize the
drug closure, but I'm not understanding part of it.

Modified (broken) Modular Implementation

Modified Java Code:

New drugs.groovy

Modified patient.groovy

I think things are breaking down in the new drugs() {...} closure. drugClosure is defined in
a separate file and I'm having a heck of a time trying to find information that explains how to
include/reference/inject that into patient {...}

Any help would be much appreciated.

John Dee

Joined: May 13, 2010
Posts: 3
I found the solution:

The the builder class needs a new method I named as 'include(Closure c, Object args)' method within the builder.


Modified patient.groovy

I agree. Here's the link:
subject: Modular Closures for Builders (FactoryBuilderSupport)
It's not a secret anymore!