Grails, Technology

Closure Delegate using Groovy “with” Method and decorating code with multiple assignments

Groovy is an expressive language, that is what we are going to talk about making the usage of "with" method for specifying closure delegate and making our code more succinct (brief and clearly expressed). In my recent project, I was writing a code to resolve tenant and setting some properties to object tenant. ...

by Tarun Pareek
Tag: delegate
23-Jul-2015

Grails

MetaProgramming with MetaClass

As we all know that groovy is a dynamic programming language, so we can add any method to any class at runtime. First, let’s see a small and simple example of metaProgamming given below, in which we are adding a method (isEvent) into an Integer class. [groovy] Integer.metaClass.isEven = { -> // only (->) sign indicates that...

by Amit Kumar
Tag: delegate
24-Sep-2012

Grails

What is Delegate ??

Suppose a scenario, where User and Account classes are linked as below: [groovy] class Account { String email String password // ... other fields } class User { Account account String name String address // ... other fields } [/groovy] At the time of creating a new User, and accessing the user...

by Amit Kumar
Tag: delegate
25-Aug-2012