Chapter 11Exploring Metaobject Protocol (MOP)

In Java, we can use reflection at runtime to explore our program’s structure, plus its classes, their methods, and the parameters they take. However, we’re still restricted to the static structure we’ve created. We can’t change an object’s type or let it acquire behavior dynamically at runtime—at least not yet. Imagine if we could add methods and behavior dynamically based on the current state of our application or the inputs it receives. This would make our code flexible, and we could be creative and productive. Well, we don’t have to imagine that anymore—metaprogramming provides this functionality in Groovy.

How extensible can we design applications to be with these features? Quite. I recently ...

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.