15.3 Review of MOP Techniques
We’ve seen a number of options to intercept, inject, and synthesize methods. In this section, we’ll figure out which option is right for us.
Options for Method Interception
We discussed method interception in Chapter 12, Intercepting Methods Using MOP, and
Section 13.1, Injecting Methods Using Categories. We can use GroovyInterceptable,
ExpandoMetaClass, or categories.
If we have the privileges to modify the class source, we can implement GroovyInterceptable
on the class we want to intercept method calls. The effort is as simple as implementing
invokeMethod
.
If we can’t modify the class or if the class is a Java class, then we can use
ExpandoMetaClass or categories. ExpandoMetaClass clearly ...
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