MOP: Meta Object Protocol

In object-oriented programming, a metaclass is a class whose instances are classes. Just as an ordinary class defines the behavior of certain objects, a metaclass defines the behavior of certain classes and their instances. Not all object-oriented programming languages support metaclasses. Among those that do, the extent to which metaclasses can override any given aspect of class behavior varies. Each language has its own metaobject protocol, a set of rules that govern how objects, classes, and metaclasses interact.

Each groovy object has a metaClass that is used to manage the dynamic nature of the language. This class intercepts calls to groovy objects to ensure that the appropriate grooviness can be added.

Everytime you invoke a method on an object, Groovy's dispatch mechanism routes the call through the MetaClass related to the object, so if you can alter the MetaClass in any way you may change the object's behavior at runtime.



Subsecciones
Casiano Rodríguez León
2010-04-30