SlideShare a Scribd company logo
1 of 20
DSL in Groovy 胡键 www.groovyq.net
DSL in Groovy Domain Specific Language
DSL in Groovy 几个Groovy DSL的例子
GroovyBuilder
Grails Config Dependency Config URL Mapping GORM DataSource Modeling Query ……
Spock
用Groovy构建DSL:基础 Method 参数1, 参数2, …
用Groovy构建DSL:基础 Closure
用Groovy构建DSL:基础 MOP methodMissing invokeMethod metaClass
用Groovy构建DSL:基础 Builder
My DSL:例一 利用methodMissing模拟GORM部分方法 实现: mockDomain.groovy
My DSL:例一 利用methodMissing/invokeMethod 优点:简单 缺点: 不太适合稍微复杂一点的DSL,如方法嵌套 要实现的方法太多时,实现逻辑也会变复杂,需做特殊处理
My DSL:例二 扩展BuilderSupport实现自己的XML Builder 实现 myBuilder.groovy 关键方法: setParent createNode nodeCompleted
My DSL:例二 扩展BuilderSupport 优点:直观,动态 缺点:缺乏结构化
My DSL:例三 FactoryBuilderSupport将Grails Domain Class输出成另一个工具所需的DSL。 实现: DiagramFactoryBuilder.groovy
My DSL:例三 使用3步骤 定义并实现各节点对象 实现各节点对应的Factory,继承AbstractFactory 注册各节点的Factory,在FactoryBuilderSupport 2个关键类 FactoryBuilderSupport AbstractFactory
My DSL:例三 利用FactoryBuilderSupport 优点:结构化 缺点:需先确定DSL的语法节点,对于不可预期的节点无法处理
My DSL:例四 扩展Script类模拟机器人控制脚本。(受http://groovyconsole.appspot.com/script/112001启发) 实现 Robot.groovy
My DSL:例四 扩展Script类 优点:非常适合作为配置文件、规则文件提供给应用的用户使用 缺点:无法直接供应用中的类使用
OpenParty西安:DSL in Groovy

More Related Content

Viewers also liked

Building DSLs with Groovy
Building DSLs with GroovyBuilding DSLs with Groovy
Building DSLs with GroovySten Anderson
 
Spring one 2012 Groovy as a weapon of maas PaaSification
Spring one 2012 Groovy as a weapon of maas PaaSificationSpring one 2012 Groovy as a weapon of maas PaaSification
Spring one 2012 Groovy as a weapon of maas PaaSificationNenad Bogojevic
 
Groovy DSLs, from Beginner to Expert - Guillaume Laforge and Paul King - Spri...
Groovy DSLs, from Beginner to Expert - Guillaume Laforge and Paul King - Spri...Groovy DSLs, from Beginner to Expert - Guillaume Laforge and Paul King - Spri...
Groovy DSLs, from Beginner to Expert - Guillaume Laforge and Paul King - Spri...Guillaume Laforge
 
GR8Conf 2009: Practical Groovy DSL by Guillaume Laforge
GR8Conf 2009: Practical Groovy DSL by Guillaume LaforgeGR8Conf 2009: Practical Groovy DSL by Guillaume Laforge
GR8Conf 2009: Practical Groovy DSL by Guillaume LaforgeGR8Conf
 
GGUG:Practical DSL Design
GGUG:Practical DSL DesignGGUG:Practical DSL Design
GGUG:Practical DSL DesignSkills Matter
 
Building an Extensible, Resumable DSL on Top of Apache Groovy
Building an Extensible, Resumable DSL on Top of Apache GroovyBuilding an Extensible, Resumable DSL on Top of Apache Groovy
Building an Extensible, Resumable DSL on Top of Apache Groovyjgcloudbees
 

Viewers also liked (9)

Os Secoske
Os SecoskeOs Secoske
Os Secoske
 
Groovy DSL
Groovy DSLGroovy DSL
Groovy DSL
 
Building DSLs with Groovy
Building DSLs with GroovyBuilding DSLs with Groovy
Building DSLs with Groovy
 
Groovy to gradle
Groovy to gradleGroovy to gradle
Groovy to gradle
 
Spring one 2012 Groovy as a weapon of maas PaaSification
Spring one 2012 Groovy as a weapon of maas PaaSificationSpring one 2012 Groovy as a weapon of maas PaaSification
Spring one 2012 Groovy as a weapon of maas PaaSification
 
Groovy DSLs, from Beginner to Expert - Guillaume Laforge and Paul King - Spri...
Groovy DSLs, from Beginner to Expert - Guillaume Laforge and Paul King - Spri...Groovy DSLs, from Beginner to Expert - Guillaume Laforge and Paul King - Spri...
Groovy DSLs, from Beginner to Expert - Guillaume Laforge and Paul King - Spri...
 
GR8Conf 2009: Practical Groovy DSL by Guillaume Laforge
GR8Conf 2009: Practical Groovy DSL by Guillaume LaforgeGR8Conf 2009: Practical Groovy DSL by Guillaume Laforge
GR8Conf 2009: Practical Groovy DSL by Guillaume Laforge
 
GGUG:Practical DSL Design
GGUG:Practical DSL DesignGGUG:Practical DSL Design
GGUG:Practical DSL Design
 
Building an Extensible, Resumable DSL on Top of Apache Groovy
Building an Extensible, Resumable DSL on Top of Apache GroovyBuilding an Extensible, Resumable DSL on Top of Apache Groovy
Building an Extensible, Resumable DSL on Top of Apache Groovy
 

Similar to OpenParty西安:DSL in Groovy

这年头,你只需要懂Node webkit
这年头,你只需要懂Node webkit这年头,你只需要懂Node webkit
这年头,你只需要懂Node webkitLainZQ
 
MongoDB Basics and Tutorial
MongoDB Basics and TutorialMongoDB Basics and Tutorial
MongoDB Basics and TutorialHo Kim
 
Bluemix Node-Red Part II
Bluemix Node-Red Part IIBluemix Node-Red Part II
Bluemix Node-Red Part IIJoseph Chang
 
Introduction to Golang final
Introduction to Golang final Introduction to Golang final
Introduction to Golang final Paul Chao
 
Pyramid框架介绍
Pyramid框架介绍Pyramid框架介绍
Pyramid框架介绍panjunyong
 
模块加载策略 - 2012 SDCC, 北京
模块加载策略 - 2012 SDCC, 北京模块加载策略 - 2012 SDCC, 北京
模块加载策略 - 2012 SDCC, 北京Joseph Chiang
 
Rubyonrails(Chinese)
Rubyonrails(Chinese)Rubyonrails(Chinese)
Rubyonrails(Chinese)heisda
 
基于Android ndk的软件开发简介 放映
基于Android ndk的软件开发简介 放映基于Android ndk的软件开发简介 放映
基于Android ndk的软件开发简介 放映heyfluke
 
基于Android ndk的软件开发简介 放映
基于Android ndk的软件开发简介 放映基于Android ndk的软件开发简介 放映
基于Android ndk的软件开发简介 放映heyfluke
 
Nosql七种武器之长生剑 mongodb的使用介绍
Nosql七种武器之长生剑 mongodb的使用介绍Nosql七种武器之长生剑 mongodb的使用介绍
Nosql七种武器之长生剑 mongodb的使用介绍yczealot
 
淺談 Groovy 與 Gradle
淺談 Groovy 與 Gradle淺談 Groovy 與 Gradle
淺談 Groovy 與 GradleJustin Lin
 
Gradle 和 Android Studio --- Jason Ko
Gradle 和 Android Studio --- Jason KoGradle 和 Android Studio --- Jason Ko
Gradle 和 Android Studio --- Jason Ko力中 柯
 
Responsive Web Design [rebuild as design]
Responsive Web Design [rebuild as design]Responsive Web Design [rebuild as design]
Responsive Web Design [rebuild as design]Benny Chak
 
Java DSL与动态代码生成技术的应用 (上集:DSL部分)
Java DSL与动态代码生成技术的应用 (上集:DSL部分)Java DSL与动态代码生成技术的应用 (上集:DSL部分)
Java DSL与动态代码生成技术的应用 (上集:DSL部分)悦 温
 
NodeJS基礎教學&簡介
NodeJS基礎教學&簡介NodeJS基礎教學&簡介
NodeJS基礎教學&簡介GO LL
 
Static Code Analysis 靜態程式碼分析
Static Code Analysis 靜態程式碼分析Static Code Analysis 靜態程式碼分析
Static Code Analysis 靜態程式碼分析Bill Lin
 
Fiddler使用技巧
Fiddler使用技巧Fiddler使用技巧
Fiddler使用技巧明 李
 
Vic weekly learning_20160504
Vic weekly learning_20160504Vic weekly learning_20160504
Vic weekly learning_20160504LearningTech
 
Groovy:Candy for Java Developers
Groovy:Candy for Java DevelopersGroovy:Candy for Java Developers
Groovy:Candy for Java Developersfoxgem
 

Similar to OpenParty西安:DSL in Groovy (20)

这年头,你只需要懂Node webkit
这年头,你只需要懂Node webkit这年头,你只需要懂Node webkit
这年头,你只需要懂Node webkit
 
MongoDB Basics and Tutorial
MongoDB Basics and TutorialMongoDB Basics and Tutorial
MongoDB Basics and Tutorial
 
Bluemix Node-Red Part II
Bluemix Node-Red Part IIBluemix Node-Red Part II
Bluemix Node-Red Part II
 
Introduction to Golang final
Introduction to Golang final Introduction to Golang final
Introduction to Golang final
 
5 Bluemix-LoRa application III
5 Bluemix-LoRa application III5 Bluemix-LoRa application III
5 Bluemix-LoRa application III
 
Pyramid框架介绍
Pyramid框架介绍Pyramid框架介绍
Pyramid框架介绍
 
模块加载策略 - 2012 SDCC, 北京
模块加载策略 - 2012 SDCC, 北京模块加载策略 - 2012 SDCC, 北京
模块加载策略 - 2012 SDCC, 北京
 
Rubyonrails(Chinese)
Rubyonrails(Chinese)Rubyonrails(Chinese)
Rubyonrails(Chinese)
 
基于Android ndk的软件开发简介 放映
基于Android ndk的软件开发简介 放映基于Android ndk的软件开发简介 放映
基于Android ndk的软件开发简介 放映
 
基于Android ndk的软件开发简介 放映
基于Android ndk的软件开发简介 放映基于Android ndk的软件开发简介 放映
基于Android ndk的软件开发简介 放映
 
Nosql七种武器之长生剑 mongodb的使用介绍
Nosql七种武器之长生剑 mongodb的使用介绍Nosql七种武器之长生剑 mongodb的使用介绍
Nosql七种武器之长生剑 mongodb的使用介绍
 
淺談 Groovy 與 Gradle
淺談 Groovy 與 Gradle淺談 Groovy 與 Gradle
淺談 Groovy 與 Gradle
 
Gradle 和 Android Studio --- Jason Ko
Gradle 和 Android Studio --- Jason KoGradle 和 Android Studio --- Jason Ko
Gradle 和 Android Studio --- Jason Ko
 
Responsive Web Design [rebuild as design]
Responsive Web Design [rebuild as design]Responsive Web Design [rebuild as design]
Responsive Web Design [rebuild as design]
 
Java DSL与动态代码生成技术的应用 (上集:DSL部分)
Java DSL与动态代码生成技术的应用 (上集:DSL部分)Java DSL与动态代码生成技术的应用 (上集:DSL部分)
Java DSL与动态代码生成技术的应用 (上集:DSL部分)
 
NodeJS基礎教學&簡介
NodeJS基礎教學&簡介NodeJS基礎教學&簡介
NodeJS基礎教學&簡介
 
Static Code Analysis 靜態程式碼分析
Static Code Analysis 靜態程式碼分析Static Code Analysis 靜態程式碼分析
Static Code Analysis 靜態程式碼分析
 
Fiddler使用技巧
Fiddler使用技巧Fiddler使用技巧
Fiddler使用技巧
 
Vic weekly learning_20160504
Vic weekly learning_20160504Vic weekly learning_20160504
Vic weekly learning_20160504
 
Groovy:Candy for Java Developers
Groovy:Candy for Java DevelopersGroovy:Candy for Java Developers
Groovy:Candy for Java Developers
 

More from foxgem

浅说Vertx
浅说Vertx浅说Vertx
浅说Vertxfoxgem
 
Our Choice:电子书的新交互方式探讨
Our Choice:电子书的新交互方式探讨Our Choice:电子书的新交互方式探讨
Our Choice:电子书的新交互方式探讨foxgem
 
移动开发的性能优化
移动开发的性能优化移动开发的性能优化
移动开发的性能优化foxgem
 
持续交付 - 使用云计算和虚拟化技术
持续交付 - 使用云计算和虚拟化技术持续交付 - 使用云计算和虚拟化技术
持续交付 - 使用云计算和虚拟化技术foxgem
 
Grails:下一代Java Web开发框架
Grails:下一代Java Web开发框架Grails:下一代Java Web开发框架
Grails:下一代Java Web开发框架foxgem
 
Groovy for Java Programmer
Groovy for Java ProgrammerGroovy for Java Programmer
Groovy for Java Programmerfoxgem
 
OpenParty西安:What does DevOps mean?
OpenParty西安:What does DevOps mean?OpenParty西安:What does DevOps mean?
OpenParty西安:What does DevOps mean?foxgem
 
OpenParty西安:How to be a good copycat?
OpenParty西安:How to be a good copycat?OpenParty西安:How to be a good copycat?
OpenParty西安:How to be a good copycat?foxgem
 

More from foxgem (8)

浅说Vertx
浅说Vertx浅说Vertx
浅说Vertx
 
Our Choice:电子书的新交互方式探讨
Our Choice:电子书的新交互方式探讨Our Choice:电子书的新交互方式探讨
Our Choice:电子书的新交互方式探讨
 
移动开发的性能优化
移动开发的性能优化移动开发的性能优化
移动开发的性能优化
 
持续交付 - 使用云计算和虚拟化技术
持续交付 - 使用云计算和虚拟化技术持续交付 - 使用云计算和虚拟化技术
持续交付 - 使用云计算和虚拟化技术
 
Grails:下一代Java Web开发框架
Grails:下一代Java Web开发框架Grails:下一代Java Web开发框架
Grails:下一代Java Web开发框架
 
Groovy for Java Programmer
Groovy for Java ProgrammerGroovy for Java Programmer
Groovy for Java Programmer
 
OpenParty西安:What does DevOps mean?
OpenParty西安:What does DevOps mean?OpenParty西安:What does DevOps mean?
OpenParty西安:What does DevOps mean?
 
OpenParty西安:How to be a good copycat?
OpenParty西安:How to be a good copycat?OpenParty西安:How to be a good copycat?
OpenParty西安:How to be a good copycat?
 

OpenParty西安:DSL in Groovy