Reader small image

You're reading from  Groovy for Domain-Specific Languages, Second Edition

Product typeBook
Published inSep 2015
Reading LevelIntermediate
Publisher
ISBN-139781849695404
Edition1st Edition
Languages
Right arrow
Author (1)
Fergal Dearle
Fergal Dearle
author image
Fergal Dearle

Fergal is a seasoned software development professional with 23 years of experience in software product development across a wide variety of technologies. He is currently principal consultant with his own software development consulting company, Dearle Technologies Ltd., engaged in design, development, and architecture for new software products for client companies. In the past Fergal has worked in lead architect and developer roles for Candle Corporation on the OMEGAMON product which is now part of IBMs Tivoli product suite as development manager for the Unix implementations of Lotus 1-2-3. In the early 1990s Fergal lead the team at Glockenspiel that developed CommonView, the first object-oriented UI framework for Microsoft Windows. The team was awarded one of the first ever Jolt Productivity Awards by Dr Dobbs Journal.
Read more about Fergal Dearle

Right arrow

Adding built-in methods


However simple our DSL might now look, the need to preface our method calls with GeeTwitter is one final piece of boilerplate code that it would be nice to remove. In some of the previous examples we have used a static import to do this, but it is still not very intuitive to a non Java/Groovy programmer why we are doing this. Since we are evaluating the DSL script ourselves, rather than allowing Groovy to do it, we still have some scope to do this.

It would certainly be nicer to be able to write:

eachFollower { 
  sendMessage it, "Thanks for taking the time to follow me!"
}

This assumes that the eachFollower method is built in to the DSL, rather than the more verbose:

GeeTwitter.eachFollower { 
  GeeTwitter.sendMessage (it, 
         "Thanks for taking the time to follow me!")
}

Groovy provides two mechanisms that allow us achieve just this. Later in the book, we will look at how we can manipulate the binding to achieve this. For this chapter, we will look at a more straightforward...

lock icon
The rest of the page is locked
Previous PageNext Page
You have been reading a chapter from
Groovy for Domain-Specific Languages, Second Edition
Published in: Sep 2015Publisher: ISBN-13: 9781849695404

Author (1)

author image
Fergal Dearle

Fergal is a seasoned software development professional with 23 years of experience in software product development across a wide variety of technologies. He is currently principal consultant with his own software development consulting company, Dearle Technologies Ltd., engaged in design, development, and architecture for new software products for client companies. In the past Fergal has worked in lead architect and developer roles for Candle Corporation on the OMEGAMON product which is now part of IBMs Tivoli product suite as development manager for the Unix implementations of Lotus 1-2-3. In the early 1990s Fergal lead the team at Glockenspiel that developed CommonView, the first object-oriented UI framework for Microsoft Windows. The team was awarded one of the first ever Jolt Productivity Awards by Dr Dobbs Journal.
Read more about Fergal Dearle