Groovy MOPping

Preview:

DESCRIPTION

Every developer dreams about big red button to do everything he needs. MOP (Metaobject protocol) in Groovy is a way to get close to that dream. There is a presentation of meta programming concepts in Groovy and what benefits you can get from it.

Citation preview

Groovy

MOPping

Izzet Mustafayev@EPAM Systems@webdizzhttp://webdizz.name

this is me● SA at EPAM Systems

● primary skill Java

● hands-on-coding with Ruby, Groovy, some

Scala

● passion about agile, clean code practices

and devops

agenda● Groovy

● MOP... what?

● AOP

● method injection/synthesis

● AST

● summary

● q&a

Groovy

Groovy is an agile dynamic language

Java is a Groovy but Groovy is not Java

Groovy supports DSL

Groovy provides statically type check

MOP...?

MOP Example GORM

class Person {

String name

Integer age

Date lastVisit

}

Person.findByName('Jack')

Groovy Objectpackage groovy.lang;

public interface GroovyObject {

Object invokeMethod(String name, Object

args);

Object getProperty(String property);

void setProperty(String property, Object

newValue);

MetaClass getMetaClass();

void setMetaClass(MetaClass metaClass);

}

Object operation

str = 'hello'

method = str.metaClass.getMetaMethod

('toUpperCase')

println method.invoke(str) // HELLO

AOP

groovy.lang.GroovyInterceptable#invokeMethod

groovy.lang.MetaClass#invokeMethod

method injection

Category

ExpandoMetaClass

Class Instance

Mixing

method synthesis

methodMissing()

ExpandoMetaClass

AST transformations

interception

injection

summary

DSL

Source Analysis

Dependency Management

references● Groovy http://groovy.codehaus.org/

● CodeNarc http://codenarc.sourceforge.net/

● Gradle http://www.gradle.org/

● Gant http://gant.codehaus.org/

● Writting DSL http://groovy.codehaus.org/Writing+Domain-

Specific+Languages

● Dynamic Groovy http://groovy.codehaus.

org/Dynamic+Groovy

● Demo sources https://github.com/webdizz/groovy-mopping

q&a

Groovy

MOPpingIzzet Mustafayev@EPAM Systems@webdizzhttp://webdizz.name

thank you!

Recommended