O'Reilly logo

Programming Groovy 2 by Venkat Subramaniam

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Method Synthesis Using methodMissing

So far we’ve been able to inject specific methods into a class or an instance. In this section, we’ll synthesize methods with flexible and dynamic names. We don’t decide the names ahead of time. In fact, we can let the users of our class decide the names as long as they follow conventions we set. When they call a nonexistent method, we can intercept it and create an implementation on the fly. The implementation is made to measure. In other words, it is created only when the users ask for it.

Method synthesis is implemented in Grails/GORM for domain classes. Suppose we have a domain class (a class that represents information persistent in a database table) Person with a number of fields (columns in the table), ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required