Borrowing methods from other classes

ExpandoMetaClass - Borrowing Methods from other classes

With ExpandoMetaClass you can also use Groovy's method pointer syntax to borrow methods from other classes. For example:

class Person {
    String name
class MortgageLender {
   def borrowMoney() {
      "buy house"

def lender = new MortgageLender()

Person.metaClass.buyHouse = lender.&borrowMoney

def p = new Person()

assert "buy house" == p.buyHouse()