14.1 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 ...
Get Programming Groovy 2 now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.