Presentation is loading. Please wait.

Presentation is loading. Please wait.

Groovy.

Similar presentations


Presentation on theme: "Groovy."— Presentation transcript:

1 Groovy

2 Overview First released in 2004 Dynamically compiled to JVM bytecode
Most Java code is syntactically valid Groovy Unlike Java, Groovy can be used as a scripting language

3 Groovy vs. Java

4 Domain Specific Languages
A DSL is a computer language that’s targeted to a particular kind of problem, rather than a general purpose language that’s aimed at any kind of software problem Three main Groovy features make it easy to write DSL’s: Method Interception - every class has an invokeMethod() method that can be overridden and will be called first when you call a non-existent method on an object of the class. Dynamic Invocation - Groovy can call methods and get and set properties/fields of objects dynamically. Closures + Delegates – A closure in Groovy is an open, anonymous, block of code that can take arguments, return a value, and be assigned to a variable. The context in which a closure is defined is stored in a closure’s delegate property and can be modified dynamically.

5 Problem Given the Customer class to the left, we want to create a Validator class that will validate the fields based on the constraints closure in the Customer class The Validator class will be instantiated and the validate() method will be called as seen on the right

6 Solution: Groovy to the rescue

7 Further Reading Closures: http://groovy-lang.org/closures.html
DSL example in more detail: Another great DSL example: More about DSL’s:


Download ppt "Groovy."

Similar presentations


Ads by Google