concept hook method in category groovy

This is an excerpt from Manning's book Groovy in Action, Second Edition.
Hook methods aren’t static. They’re instance methods. Being that, they can work with the object’s state. This state can include parameters for the hook logic. If these properties are of type Closure, then we have another example of parameterization with logic (see chapter 5).
The next listing maintains a whatToDo property of type Closure that’s called from inside a hook method. This allows changing the hook logic at runtime, and (not shown) having multiple instances of DynamicPretender using different closures.
The core of the MOP responsibilities is finding and selecting the right target method and handling the case when the requested method cannot be found. The first hook method that we’ll look at allows customizing the “missing method” case. A second one covers the case that a property access fails to find a property of the requested name. Then we’ll explore the effects of combining hook methods with closure properties to allow instance-specific hooks that can even change at runtime. We finish up with custom logic for methods that objects need to provide if they implement the GroovyObject interface.