/*** * Excerpted from "Programming Groovy", * published by The Pragmatic Bookshelf. * Copyrights apply to this code. It may not be used to create training material, * courses, books, articles, and the like. Contact us if you are in doubt. * We make no guarantees that this code is fit for any purpose. * Visit http://www.pragmaticprogrammer.com/titles/vslg for more book information. ***/ class Equipment { def calculator Equipment(calc) { calculator = calc } def simulate() { println "Running simulation" calculator() // You may send parameters as well } } eq1 = new Equipment() { println "Calculator 1" } aCalculator = { println "Calculator 2" } eq2 = new Equipment(aCalculator) eq3 = new Equipment(aCalculator) eq1.simulate() eq2.simulate() eq3.simulate()