Created
October 12, 2016 19:56
-
-
Save BenjaminHerbert/41f9964f0de18ddfdb776c4c802811fb to your computer and use it in GitHub Desktop.
DSL in Groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Behandlungsplan { | |
def count = 0 | |
def patient(String yo) { | |
println "Patient: " + yo | |
} | |
def behandlung(String yolo) { | |
println yolo | |
count ++ | |
} | |
def drucken() { | |
println count | |
} | |
static void create(Closure script) { | |
script.resolveStrategy = Closure.DELEGATE_FIRST | |
script.delegate = new Behandlungsplan() | |
script() | |
} | |
} | |
Behandlungsplan.create({ | |
patient "wilhelm busch" | |
behandlung "motorschiene" | |
behandlung "fango" | |
behandlung "schlingentisch" | |
behandlung 2 mal "manuelle therapie" | |
drucken() | |
}) | |
def plan = new Behandlungsplan() | |
plan.patient("wilhelm busch") | |
plan.behandlung("motoschiene") | |
plan.behandlung("fango") | |
plan.behandlung("schlingentisch") | |
plan.behandlung("manuelle therapie") | |
plan.drucken() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment