Leveraging Groovy for Capturing Business Rules

Groovy has excellent support for the creation of Domain Specific Languages (DSLs). Such DSLs can be particularly useful when writing business rules. Rules can be written in English-like phrases which are straight-forward to read or write (by non-developers) yet can be fully executable code corresponding to a layer over the top of a traditional logic solving API. This talk illustrates various DSLs, highlights several logic solving APIs and looks at the pros and cons of the various approaches (including tool support, flexibility, lock-in).

Whilst Groovy is the language of choice for this talk, the techniques and principles are not specific to Groovy and apply readily to your favourite modern scripting language. The “logic solving” APIs being highlighted are primarily Choco, Drools Expert and Drools Planner but again these are just illustrative of the logic APIs that you can use when writing a DSL layer. We look at the benefits and costs when writing such DSL layers, numerous real-world examples and the all-important aspects of tooling; covering what non-developer, developer and cloud tooling is available with this kind of approach.

To give a flavour of the talk, here is a snippet from one of the code examples (Einstein’s riddle) - yes, this is code:

the Briton has a red house
the owner of the green house drinks coffee
the owner of the yellow house plays baseball
the person known to play football keeps birds
the man known to play tennis drinks beer
the green house is on the left side of the white house
the man known to play volleyball lives next to the one who keeps cats
the Norwegian lives next to the blue house

When discussing this example, we look at how you create and debug such code, illustrate how several APIs can be used underneath this DSL layer, discuss the costs involved in creating the above DSL in its basic form and in more complex forms that allow type checking, code completion etc. and options for parallelism and cloud deployment.


About Paul King

Paul King, a member of the OCI Groovy team, leads ASERT, an organization based in Brisbane, Australia, which provides software development, training, and mentoring services to customers looking to embrace new technologies, harness best practices, and innovate. He has been contributing to open source projects for nearly 20 years and is an active committer on numerous projects, including Groovy. Paul speaks at international conferences, publishes in software magazines and journals, and is a co-author of Manning's best-seller, Groovy in Action.

More About Paul »