SlideShare a Scribd company logo
Mopping Up With Groovy*




Brent Snook
brent@fuglylogic.com    *obligatory lame pun
What is a MOP?
Duck Typing

• POJ (Plain Old Java) – you can
  interact with an object based on
  what it is (Class)

• Groovy – you can interact based on
  which properties and methods are
  available on the object (MetaClass)
Modifying Class Behaviour at Runtime
• AKA Monkey Patching
• AKA Duck Punching
• see whytheluckystiff's My Complete List Of
  Substitute Names For The Maneuver We
  Now Know To Be Monkeypatching
Why Do It?
• it has an amusing name
• it makes you more attractive to the opposite
  (or same) sex
• it allows you to write more succinct,
  expressive code
But I Feel Dirty …
• you may need to change how you
  think about things
• the laws are different in the duck
  typing universe
• question old attitudes and
  conventions
How Does Groovy
Implement a MOP?
The MetaClass
• every Groovy object has one
• richer introspection and invocation interface
  than Java Class
• you can set the MetaClass for an object to
  change the rules for how it can behave
The Final Shape of an Object


         Added Methods

 Class   ++ Properties
                         =   MetaClass
The ExpandoMetaClass
• core of Groovy metaprogramming
• allows you to customise behaviour on the fly
• when you ask a newly created GroovyObject
  for its metaClass, this is what you get back



                   <<interface>>
                                   ExpandoMetaClass
 GroovyObject       MetaClass
What Can You Do With It?
•   borrow methods from other classes
•   add or override constructors
•   dynamically create method names
•   add methods to interfaces
•   add or override instance methods
•   add or override properties
•   add or override static methods
    http://groovy.codehaus.org/ExpandoMetaClass
Adding a Class Method
Adding a Property
Overriding an Instance Method
The Same In Ruby
Invocation/Access Hooks
•   invokeMethod
•   getProperty
•   setProperty
•   propertyMissing
•   methodMissing
AOP with invokeMethod
Flexible Methods with methodMissing
MOP!!...huh! What is
  it Good For?
Syntactic Sugar
Mocking/Stubbing Behaviour
DSL - The Original Class
Adding Some MOP Trickery
Icecream Time
Replacing/Simplifying Frameworks
              and Patterns
•   Spring, EasyMock/JMock
•   circumvent the rigidity of the Java language
•   patterns like Builder
•   Dependency Injection
•   with Groovy these can be simplified or
    disappear altogether
Finally
The Pros and Cons
Pros                 Cons
• flexibility        • sometimes clunky
• extensibility        syntax
• power              • slower performance
With Great Power…
• don’t get wowed by the coolness factor
• remember to KISS
• the end result should be more
  understandable, not less
• keep pushing the boundaries but exercise
  judgment
Further Reading and References
•   http://www.gnu.org/software/guile/docs/goops/Metaobjects-
    and-the-Metaobject-Protocol.html#Metaobjects%20and%20the
    %20Metaobject%20Protocol
•   http://en.wikipedia.org/wiki/Meta-object_protocol
•   http://www.grails-exchange.com/files/GraemeRocher%20-
    %20Keynote-DynamicGroovyMetaMagic.pdf
•   http://groovy.codehaus.org/ExpandoMetaClass
•   http://whytheluckystiff.net/articles/
    seeingMetaclassesClearly.html
•   http://groovy.codehaus.org/ExpandoMetaClass
•   http://hackety.org/2007/08/10/
    myCompleteListOfSubstitutePhrasesForTheActWeNowKnowTo
    BeMonkeypatching.html
•   Groovy In Action

More Related Content

Viewers also liked

General Cleaning Module 3 PowerPoint
General Cleaning Module 3 PowerPointGeneral Cleaning Module 3 PowerPoint
General Cleaning Module 3 PowerPointrgochnour
 
IRC Internship reflection
IRC Internship reflectionIRC Internship reflection
IRC Internship reflectionrgochnour
 
General Cleaning Module 2 PowerPoint
General Cleaning Module 2 PowerPointGeneral Cleaning Module 2 PowerPoint
General Cleaning Module 2 PowerPointrgochnour
 
Bed making
Bed makingBed making
Bed making
Bed makingBed making
Bed makingaifl
 
FATbit Immortalizes Neil Patel With Graphic Wiki – Review & Share!
FATbit Immortalizes Neil Patel With Graphic Wiki – Review & Share!FATbit Immortalizes Neil Patel With Graphic Wiki – Review & Share!
FATbit Immortalizes Neil Patel With Graphic Wiki – Review & Share!
FATbit Technologies
 
Housekeeping dept.
Housekeeping dept.Housekeeping dept.
Housekeeping dept.
Richie Mark-Hyun Neul Kim
 
Hotel housekeeping
Hotel housekeepingHotel housekeeping

Viewers also liked (9)

General Cleaning Module 3 PowerPoint
General Cleaning Module 3 PowerPointGeneral Cleaning Module 3 PowerPoint
General Cleaning Module 3 PowerPoint
 
IRC Internship reflection
IRC Internship reflectionIRC Internship reflection
IRC Internship reflection
 
Clil
ClilClil
Clil
 
General Cleaning Module 2 PowerPoint
General Cleaning Module 2 PowerPointGeneral Cleaning Module 2 PowerPoint
General Cleaning Module 2 PowerPoint
 
Bed making
Bed makingBed making
Bed making
 
Bed making
Bed makingBed making
Bed making
 
FATbit Immortalizes Neil Patel With Graphic Wiki – Review & Share!
FATbit Immortalizes Neil Patel With Graphic Wiki – Review & Share!FATbit Immortalizes Neil Patel With Graphic Wiki – Review & Share!
FATbit Immortalizes Neil Patel With Graphic Wiki – Review & Share!
 
Housekeeping dept.
Housekeeping dept.Housekeeping dept.
Housekeeping dept.
 
Hotel housekeeping
Hotel housekeepingHotel housekeeping
Hotel housekeeping
 

Similar to Mopping Up With Groovy

Groovy And Grails Introduction
Groovy And Grails IntroductionGroovy And Grails Introduction
Groovy And Grails Introduction
Eric Weimer
 
Deliverance: Plone theming without the learning curve from Plone Symposium Ea...
Deliverance: Plone theming without the learning curve from Plone Symposium Ea...Deliverance: Plone theming without the learning curve from Plone Symposium Ea...
Deliverance: Plone theming without the learning curve from Plone Symposium Ea...
Jazkarta, Inc.
 
Groovy Metaprogramming for Dummies
Groovy Metaprogramming for DummiesGroovy Metaprogramming for Dummies
Groovy Metaprogramming for Dummies
Darren Cruse
 
JavaOne 2008 - TS-5793 - Groovy and Grails, changing the landscape of Java EE...
JavaOne 2008 - TS-5793 - Groovy and Grails, changing the landscape of Java EE...JavaOne 2008 - TS-5793 - Groovy and Grails, changing the landscape of Java EE...
JavaOne 2008 - TS-5793 - Groovy and Grails, changing the landscape of Java EE...Guillaume Laforge
 
Groovy MOPping
Groovy MOPpingGroovy MOPping
Groovy MOPping
Izzet Mustafaiev
 
Feelin' Groovy: An Afternoon of Reflexive Metaprogramming
Feelin' Groovy: An Afternoon of Reflexive MetaprogrammingFeelin' Groovy: An Afternoon of Reflexive Metaprogramming
Feelin' Groovy: An Afternoon of Reflexive Metaprogramming
Matt Stine
 
Java to Golang: An intro by Ryan Dawson Seldon.io
Java to Golang: An intro by Ryan Dawson Seldon.ioJava to Golang: An intro by Ryan Dawson Seldon.io
Java to Golang: An intro by Ryan Dawson Seldon.io
Mauricio (Salaboy) Salatino
 
Grooscript greach
Grooscript greachGrooscript greach
Grooscript greach
Jorge Franco Leza
 
Rapid Prototyping With J Query
Rapid Prototyping With J QueryRapid Prototyping With J Query
Rapid Prototyping With J Query
Bootstrap
 
Ajax Tutorial
Ajax TutorialAjax Tutorial
Ajax Tutorialoscon2007
 
New Ideas for Old Code - Greach
New Ideas for Old Code - GreachNew Ideas for Old Code - Greach
New Ideas for Old Code - Greach
HamletDRC
 
Groovy And Grails
Groovy And GrailsGroovy And Grails
Groovy And Grails
William Grosso
 
Grails @ Java User Group Silicon Valley
Grails @ Java User Group Silicon ValleyGrails @ Java User Group Silicon Valley
Grails @ Java User Group Silicon Valley
Sven Haiges
 
Grooming with Groovy
Grooming with GroovyGrooming with Groovy
Grooming with Groovy
Dhaval Dalal
 
Metaprogramming Techniques In Groovy And Grails
Metaprogramming Techniques In Groovy And GrailsMetaprogramming Techniques In Groovy And Grails
Metaprogramming Techniques In Groovy And GrailszenMonkey
 
Introduction to Groovy runtime metaprogramming and AST transforms
Introduction to Groovy runtime metaprogramming and AST transformsIntroduction to Groovy runtime metaprogramming and AST transforms
Introduction to Groovy runtime metaprogramming and AST transforms
Marcin Grzejszczak
 
Ola Bini Evolving The Java Platform
Ola Bini Evolving The Java PlatformOla Bini Evolving The Java Platform
Ola Bini Evolving The Java Platformdeimos
 
Metaprogramming with Groovy
Metaprogramming with GroovyMetaprogramming with Groovy
Metaprogramming with Groovy
Ali Tanwir
 
MetaProgramming with Groovy
MetaProgramming with GroovyMetaProgramming with Groovy
MetaProgramming with Groovy
NexThoughts Technologies
 

Similar to Mopping Up With Groovy (20)

Groovy And Grails Introduction
Groovy And Grails IntroductionGroovy And Grails Introduction
Groovy And Grails Introduction
 
Deliverance: Plone theming without the learning curve from Plone Symposium Ea...
Deliverance: Plone theming without the learning curve from Plone Symposium Ea...Deliverance: Plone theming without the learning curve from Plone Symposium Ea...
Deliverance: Plone theming without the learning curve from Plone Symposium Ea...
 
Groovy Metaprogramming for Dummies
Groovy Metaprogramming for DummiesGroovy Metaprogramming for Dummies
Groovy Metaprogramming for Dummies
 
JavaOne 2008 - TS-5793 - Groovy and Grails, changing the landscape of Java EE...
JavaOne 2008 - TS-5793 - Groovy and Grails, changing the landscape of Java EE...JavaOne 2008 - TS-5793 - Groovy and Grails, changing the landscape of Java EE...
JavaOne 2008 - TS-5793 - Groovy and Grails, changing the landscape of Java EE...
 
Groovy MOPping
Groovy MOPpingGroovy MOPping
Groovy MOPping
 
Feelin' Groovy: An Afternoon of Reflexive Metaprogramming
Feelin' Groovy: An Afternoon of Reflexive MetaprogrammingFeelin' Groovy: An Afternoon of Reflexive Metaprogramming
Feelin' Groovy: An Afternoon of Reflexive Metaprogramming
 
Java to Golang: An intro by Ryan Dawson Seldon.io
Java to Golang: An intro by Ryan Dawson Seldon.ioJava to Golang: An intro by Ryan Dawson Seldon.io
Java to Golang: An intro by Ryan Dawson Seldon.io
 
Grooscript greach
Grooscript greachGrooscript greach
Grooscript greach
 
Whats New In Groovy 1.6?
Whats New In Groovy 1.6?Whats New In Groovy 1.6?
Whats New In Groovy 1.6?
 
Rapid Prototyping With J Query
Rapid Prototyping With J QueryRapid Prototyping With J Query
Rapid Prototyping With J Query
 
Ajax Tutorial
Ajax TutorialAjax Tutorial
Ajax Tutorial
 
New Ideas for Old Code - Greach
New Ideas for Old Code - GreachNew Ideas for Old Code - Greach
New Ideas for Old Code - Greach
 
Groovy And Grails
Groovy And GrailsGroovy And Grails
Groovy And Grails
 
Grails @ Java User Group Silicon Valley
Grails @ Java User Group Silicon ValleyGrails @ Java User Group Silicon Valley
Grails @ Java User Group Silicon Valley
 
Grooming with Groovy
Grooming with GroovyGrooming with Groovy
Grooming with Groovy
 
Metaprogramming Techniques In Groovy And Grails
Metaprogramming Techniques In Groovy And GrailsMetaprogramming Techniques In Groovy And Grails
Metaprogramming Techniques In Groovy And Grails
 
Introduction to Groovy runtime metaprogramming and AST transforms
Introduction to Groovy runtime metaprogramming and AST transformsIntroduction to Groovy runtime metaprogramming and AST transforms
Introduction to Groovy runtime metaprogramming and AST transforms
 
Ola Bini Evolving The Java Platform
Ola Bini Evolving The Java PlatformOla Bini Evolving The Java Platform
Ola Bini Evolving The Java Platform
 
Metaprogramming with Groovy
Metaprogramming with GroovyMetaprogramming with Groovy
Metaprogramming with Groovy
 
MetaProgramming with Groovy
MetaProgramming with GroovyMetaProgramming with Groovy
MetaProgramming with Groovy
 

More from fuglylogic

It's Full of Stars - Building, Measuring and Learning With Events
It's Full of Stars - Building, Measuring and Learning With EventsIt's Full of Stars - Building, Measuring and Learning With Events
It's Full of Stars - Building, Measuring and Learning With Events
fuglylogic
 
The Daily Grind - Milling Stories to Reduce Risk
The Daily Grind - Milling Stories to Reduce RiskThe Daily Grind - Milling Stories to Reduce Risk
The Daily Grind - Milling Stories to Reduce Risk
fuglylogic
 
Agile/UX: Making the Marriage Work
Agile/UX: Making the Marriage WorkAgile/UX: Making the Marriage Work
Agile/UX: Making the Marriage Work
fuglylogic
 
Microservices Without the Macrocost
Microservices Without the MacrocostMicroservices Without the Macrocost
Microservices Without the Macrocost
fuglylogic
 
Building the Right Thing
Building the Right ThingBuilding the Right Thing
Building the Right Thing
fuglylogic
 
Bumps - Live Features with Google Wave and Cucumber
Bumps - Live Features with Google Wave and CucumberBumps - Live Features with Google Wave and Cucumber
Bumps - Live Features with Google Wave and Cucumber
fuglylogic
 
Wrangling Your Stuff
Wrangling Your StuffWrangling Your Stuff
Wrangling Your Stuff
fuglylogic
 
Trio of Gems
Trio of GemsTrio of Gems
Trio of Gems
fuglylogic
 
BDD: What's in it for me?
BDD: What's in it for me?BDD: What's in it for me?
BDD: What's in it for me?
fuglylogic
 

More from fuglylogic (10)

It's Full of Stars - Building, Measuring and Learning With Events
It's Full of Stars - Building, Measuring and Learning With EventsIt's Full of Stars - Building, Measuring and Learning With Events
It's Full of Stars - Building, Measuring and Learning With Events
 
The Daily Grind - Milling Stories to Reduce Risk
The Daily Grind - Milling Stories to Reduce RiskThe Daily Grind - Milling Stories to Reduce Risk
The Daily Grind - Milling Stories to Reduce Risk
 
Agile/UX: Making the Marriage Work
Agile/UX: Making the Marriage WorkAgile/UX: Making the Marriage Work
Agile/UX: Making the Marriage Work
 
Microservices Without the Macrocost
Microservices Without the MacrocostMicroservices Without the Macrocost
Microservices Without the Macrocost
 
Building the Right Thing
Building the Right ThingBuilding the Right Thing
Building the Right Thing
 
Bumps - Live Features with Google Wave and Cucumber
Bumps - Live Features with Google Wave and CucumberBumps - Live Features with Google Wave and Cucumber
Bumps - Live Features with Google Wave and Cucumber
 
Wrangling Your Stuff
Wrangling Your StuffWrangling Your Stuff
Wrangling Your Stuff
 
Trio of Gems
Trio of GemsTrio of Gems
Trio of Gems
 
BDD: What's in it for me?
BDD: What's in it for me?BDD: What's in it for me?
BDD: What's in it for me?
 
We All Wii
We All WiiWe All Wii
We All Wii
 

Recently uploaded

Mind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AIMind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AI
Kumud Singh
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
ControlCase
 
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdfUni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems S.M.S.A.
 
Large Language Model (LLM) and it’s Geospatial Applications
Large Language Model (LLM) and it’s Geospatial ApplicationsLarge Language Model (LLM) and it’s Geospatial Applications
Large Language Model (LLM) and it’s Geospatial Applications
Rohit Gautam
 
GridMate - End to end testing is a critical piece to ensure quality and avoid...
GridMate - End to end testing is a critical piece to ensure quality and avoid...GridMate - End to end testing is a critical piece to ensure quality and avoid...
GridMate - End to end testing is a critical piece to ensure quality and avoid...
ThomasParaiso2
 
Microsoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdfMicrosoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdf
Uni Systems S.M.S.A.
 
20240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 202420240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 2024
Matthew Sinclair
 
By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024
Pierluigi Pugliese
 
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
Neo4j
 
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
名前 です男
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
Kari Kakkonen
 
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
Neo4j
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
Matthew Sinclair
 
Full-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalizationFull-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalization
Zilliz
 
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
SOFTTECHHUB
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
James Anderson
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance
 
UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5
DianaGray10
 
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionGenerative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Aggregage
 
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdfUnlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Malak Abu Hammad
 

Recently uploaded (20)

Mind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AIMind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AI
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
 
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdfUni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdf
 
Large Language Model (LLM) and it’s Geospatial Applications
Large Language Model (LLM) and it’s Geospatial ApplicationsLarge Language Model (LLM) and it’s Geospatial Applications
Large Language Model (LLM) and it’s Geospatial Applications
 
GridMate - End to end testing is a critical piece to ensure quality and avoid...
GridMate - End to end testing is a critical piece to ensure quality and avoid...GridMate - End to end testing is a critical piece to ensure quality and avoid...
GridMate - End to end testing is a critical piece to ensure quality and avoid...
 
Microsoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdfMicrosoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdf
 
20240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 202420240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 2024
 
By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024
 
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
 
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
 
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
 
Full-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalizationFull-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalization
 
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
 
UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5
 
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionGenerative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to Production
 
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdfUnlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
 

Mopping Up With Groovy

  • 1. Mopping Up With Groovy* Brent Snook brent@fuglylogic.com *obligatory lame pun
  • 2. What is a MOP?
  • 3. Duck Typing • POJ (Plain Old Java) – you can interact with an object based on what it is (Class) • Groovy – you can interact based on which properties and methods are available on the object (MetaClass)
  • 4. Modifying Class Behaviour at Runtime • AKA Monkey Patching • AKA Duck Punching • see whytheluckystiff's My Complete List Of Substitute Names For The Maneuver We Now Know To Be Monkeypatching
  • 5. Why Do It? • it has an amusing name • it makes you more attractive to the opposite (or same) sex • it allows you to write more succinct, expressive code
  • 6. But I Feel Dirty … • you may need to change how you think about things • the laws are different in the duck typing universe • question old attitudes and conventions
  • 8. The MetaClass • every Groovy object has one • richer introspection and invocation interface than Java Class • you can set the MetaClass for an object to change the rules for how it can behave
  • 9. The Final Shape of an Object Added Methods Class ++ Properties = MetaClass
  • 10. The ExpandoMetaClass • core of Groovy metaprogramming • allows you to customise behaviour on the fly • when you ask a newly created GroovyObject for its metaClass, this is what you get back <<interface>> ExpandoMetaClass GroovyObject MetaClass
  • 11. What Can You Do With It? • borrow methods from other classes • add or override constructors • dynamically create method names • add methods to interfaces • add or override instance methods • add or override properties • add or override static methods http://groovy.codehaus.org/ExpandoMetaClass
  • 12. Adding a Class Method
  • 15. The Same In Ruby
  • 16. Invocation/Access Hooks • invokeMethod • getProperty • setProperty • propertyMissing • methodMissing
  • 18. Flexible Methods with methodMissing
  • 19. MOP!!...huh! What is it Good For?
  • 22. DSL - The Original Class
  • 23. Adding Some MOP Trickery
  • 25. Replacing/Simplifying Frameworks and Patterns • Spring, EasyMock/JMock • circumvent the rigidity of the Java language • patterns like Builder • Dependency Injection • with Groovy these can be simplified or disappear altogether
  • 27. The Pros and Cons Pros Cons • flexibility • sometimes clunky • extensibility syntax • power • slower performance
  • 28. With Great Power… • don’t get wowed by the coolness factor • remember to KISS • the end result should be more understandable, not less • keep pushing the boundaries but exercise judgment
  • 29. Further Reading and References • http://www.gnu.org/software/guile/docs/goops/Metaobjects- and-the-Metaobject-Protocol.html#Metaobjects%20and%20the %20Metaobject%20Protocol • http://en.wikipedia.org/wiki/Meta-object_protocol • http://www.grails-exchange.com/files/GraemeRocher%20- %20Keynote-DynamicGroovyMetaMagic.pdf • http://groovy.codehaus.org/ExpandoMetaClass • http://whytheluckystiff.net/articles/ seeingMetaclassesClearly.html • http://groovy.codehaus.org/ExpandoMetaClass • http://hackety.org/2007/08/10/ myCompleteListOfSubstitutePhrasesForTheActWeNowKnowTo BeMonkeypatching.html • Groovy In Action