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 ...
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