Book Image

Groovy for Domain-Specific Languages, Second Edition

By : Fergal Dearle
Book Image

Groovy for Domain-Specific Languages, Second Edition

By: Fergal Dearle

Overview of this book

Table of Contents (20 chapters)
Groovy for Domain-specific Languages Second Edition
Credits
About the Author
Acknowledgments
About the Reviewers
www.PacktPub.com
Preface
Free Chapter
1
Introduction to DSLs and Groovy
Index

Chapter 10. Building a Builder

Builders are a powerful feature of Groovy. The Groovy libraries contain an expanding set of builders for everything from XML and HTML markup to managing systems via JMX. Even so, you will always come across circumstances where the semantics of a builder would be useful in your own application.

We've seen how to build a rudimentary builder using the Groovy MOP and pretended methods, in Chapter 7, Power Groovy DSL Features. Thankfully, the Groovy libraries provide us with an easier means of developing our own builders. In this chapter, we will look at some of the ways in which we can use Groovy and the MOP to create our own builder classes:

  • To begin with, we will recap the Groovy features that enable the Groovy builder pattern, in order to understand how they work

  • We will look at how to build a rudimentary builder with features from the Groovy MOP

  • We will implement our own database seed data builder by using two of the builder support classes provided in Groovy:...