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 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access