Wednesday, October 17, 2012

SpringOne 2GX - Advanced Metaprogramming With Groovy

Presenter: Jeff Brown
4:30pm 10/17/2012

What is Metaprogramming?

In this context we mean the ability to change the behavior of a program at runtime.

Dynamic Dispatch

Ability to intercept and modify method/property access at runtime.
MOP = Meta Object Protocol

Metaprogramming Hooks

  • void setProperty(String name, value) { } - called whenever a property is set
  • def getProperty(String name) { } - called whenever a property is retrieved
  • def methodMissing(String methodName, args) { } - called when a method that does not exist is invoked
  • def propertyMissing(String name, value) { }
  • def propertyMissing(String name) { }

Closures and Delegates

Every closure has delegate, owner and resolveStrategy properties.
Every class has a meta Class: className.metaClass to which you can assign properties/methods.

Builders

ExpandoMetaClass

0 Comments:

Post a Comment

<< Home