Chapter 14MOP Method Synthesis

We can separate ways of adding behavior into two types: injection and synthesis.

We’ll use the term method injection to refer to the case in which, at code-writing time, we know the names of methods we want to add to one or more classes. With method injection we can add behavior dynamically into classes. We can add to any number of classes a set of reusable methods—like utility functions—that represent a certain functionality. We can inject methods by using categories, by using ExpandoMetaClass, or through the Groovy Mixin facility. We saw these techniques in Chapter 13, MOP Method Injection.

On the other hand, method synthesis will refer to the case in which we want to dynamically figure out the behavior ...

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.