SlideShare a Scribd company logo
GContracts


Andre Steingress
  @sternegross/@gcontracts
GR8Conf 2011: GContracts
LINZ, AUSTRIA
GR8Conf 2011: GContracts
GR8Conf 2011: GContracts
GR8Conf 2011: GContracts
GR8Conf 2011: GContracts
GR8Conf 2011: GContracts
GR8Conf 2011: GContracts
www.ejug.at
ABOUT
GCONTRACTS.
GCONTRACTS

DESIGN BY CONTRACT (tm) FOR GROOVY
 Groovy 1.7+ (was 1.6 loooong time ago)

BSD LICENSE


https://github.com/andresteingress/gcontracts
JUMP START.
LET‘S REVIEW THIS
       ACCOUNT CLASS.



Googled, found at javacoffeebreak.com
PREREQUISITES.
@Grab(
	

 group='org.gcontracts',
	

 module='gcontracts-core',
	

 version='[1.2.3,)'
)


                  no additional dependencies...
import org.gcontracts.annotations.*
3 ANNOTATIONS.
Commonalities
• special assertion types
 • specifying boolean expressions
• closure instances as annotation
  parameters


  @MyAnnotation({ param?.size() > 0 })
@Requires

• precondition

• a method‘s bouncer
@Ensures


• postcondition
• a method‘s mother
@Invariant

• class-invariant

• an object‘s god.
LET‘S REVIEW THIS
       ACCOUNT CLASS.



Googled, found at javacoffeebreak.com
INTERNALS.
@Ensures({ count() == old.count + 1 })


                          { count() == old.count + 1 }



               { result, old -> assert count() == old.count + 1 }
compile-time




                    class $_gc_closure1 extends Closure {
                        def doCall(...) {
                           // ...
                           assert count() == old.count + 1
                           // ...
                        }
                    }

                       @Requires($_gc_213123123123.class)
JVM Arguments: -ea -da

                      if ($GCONTRACTS_ENABLED) { ... }


                   org.gcontracts.ViolationTracker.init()



           $_gc_result = Putable$_gc_closure1.newInstance(this,
run-time




           this).call(element, key)


           if (org.gcontracts.ViolationTracker.violationsOccured())


               org.gcontracts.ViolationTracker.rethrowFirst()
Officially Supported since Groovy 1.8!
Works since Groovy 1.6

http://pniederw.wordpress.com/2010/03/04/3/
MORE FEATURES.
LABELING
INTERFACE CONTRACTS
INTERFACE CONTRACTS
INHERITANCE

✓INTERFACE CONTRACTS
✓ABSTRACT CLASSES
✓CONCRETE CLASSES
✓MIXED
INHERITANCE


✓ACROSS COMPILATION UNITS
MICRO CONTRACTS



       REUSABLE CONTRACT PART
MICRO CONTRACTS
Grails Integration



•   Container extends object construction time

•   @Service stereotype causes CI validation in
    @PostConstruct
GroovyDoc Integration
GR8Conf 2011: GContracts
https://github.com/andresteingress/gcontracts/wiki
ABOUT
CONTRACTS.
MR.
„DESIGN BY CONTRACT“
GR8Conf 2011: GContracts
WHY CONTRACTS?
SPOCK, JUNIT, et. al. ARE

„THE CHINAMAN IS
NOT THE ISSUE HERE,
     DUDE.“
External API Changes           New Programmers
         Changing Requirements
 Assumptions         Additional Libraries
      New Use-Cases                   More Clients
  New Knowledge    Code Conventions
External API Changes           New Programmers
         Changing Requirements
 Assumptions         Additional Libraries
      New Use-Cases                   More Clients
 New Knowledge     Code Conventions
WHAT DID YOU PROGRAM LAST WEEK?

CAN YOU RECALL YOUR THOUGHTS, MODELS?

WHY SHOULD ANYONE ELSE KNOW ABOUT THEM?
BUILD YOUR PLAYGROUND.
http://about.me/asteingress
Thank you!
"Design by Contract" is a trademark of Interactive Software Engineering.

More Related Content

PPTX
Disruptor
PDF
Rust: Reach Further
PDF
用 Go 語言打造多台機器 Scale 架構
PDF
Coding in the context era
PPTX
QA Fes 2016. Ярослав Пернеровский. Не Jav'ой единой. Пример автоматизации тес...
PDF
Rust Intro @ Roma Rust meetup
PPTX
UDPSRC GStreamer Plugin Session VIII
PPTX
Barcamp presentation
Disruptor
Rust: Reach Further
用 Go 語言打造多台機器 Scale 架構
Coding in the context era
QA Fes 2016. Ярослав Пернеровский. Не Jav'ой единой. Пример автоматизации тес...
Rust Intro @ Roma Rust meetup
UDPSRC GStreamer Plugin Session VIII
Barcamp presentation

What's hot (20)

PDF
Understanding the Disruptor
KEY
Java Core | Understanding the Disruptor: a Beginner's Guide to Hardcore Concu...
PDF
Engineering fast indexes (Deepdive)
PPSX
LMAX Disruptor as real-life example
PDF
How to Write Node.js Module
PPTX
Zero-Overhead Metaprogramming: Reflection and Metaobject Protocols Fast and w...
PDF
How to Contribute to GStreamer
PPTX
Building High-Performance Language Implementations With Low Effort
PDF
An introduction to Rust: the modern programming language to develop safe and ...
PDF
Rust: Systems Programming for Everyone
PDF
Kotlin from-scratch 3 - coroutines
PDF
Job Queue in Golang
PDF
"Развитие ветки PHP-7"
PDF
PPTX
concurrency gpars
PDF
Synchronised Multidevice Media Playback with Gstreamer
PDF
Dirty - How simple is your database?
PDF
PyCon KR 2019 sprint - RustPython by example
PDF
Масштабируемая конфигурация Nginx, Игорь Сысоев (Nginx)
PDF
Infinum android talks_10_getting groovy on android
Understanding the Disruptor
Java Core | Understanding the Disruptor: a Beginner's Guide to Hardcore Concu...
Engineering fast indexes (Deepdive)
LMAX Disruptor as real-life example
How to Write Node.js Module
Zero-Overhead Metaprogramming: Reflection and Metaobject Protocols Fast and w...
How to Contribute to GStreamer
Building High-Performance Language Implementations With Low Effort
An introduction to Rust: the modern programming language to develop safe and ...
Rust: Systems Programming for Everyone
Kotlin from-scratch 3 - coroutines
Job Queue in Golang
"Развитие ветки PHP-7"
concurrency gpars
Synchronised Multidevice Media Playback with Gstreamer
Dirty - How simple is your database?
PyCon KR 2019 sprint - RustPython by example
Масштабируемая конфигурация Nginx, Игорь Сысоев (Nginx)
Infinum android talks_10_getting groovy on android
Ad

Viewers also liked (8)

PPT
Hiring Presentation 14 Oct2010
PPT
Human capitalaudit thechazingroup_tour
PPTX
Ethan chazin franchisingprogram_15nov2014
PPT
Ethan Chazin 2011 Praxis Retreat
PDF
Ratpack On the Docks
PDF
GR8Conf 2011: Neo4j Plugin
PDF
GR8Conf 2011: Groovy 1.8 update
PDF
Groovy Powered Clean Code
Hiring Presentation 14 Oct2010
Human capitalaudit thechazingroup_tour
Ethan chazin franchisingprogram_15nov2014
Ethan Chazin 2011 Praxis Retreat
Ratpack On the Docks
GR8Conf 2011: Neo4j Plugin
GR8Conf 2011: Groovy 1.8 update
Groovy Powered Clean Code
Ad

Similar to GR8Conf 2011: GContracts (20)

PDF
Groovy 2 and beyond
PDF
Lift off with Groovy 2 at JavaOne 2013
PDF
Groovy 2.0 webinar
KEY
Groovy: to Infinity and Beyond -- JavaOne 2010 -- Guillaume Laforge
PDF
Apache Groovy's Metaprogramming Options and You
PDF
Groovy.pptx
PDF
Jggug 2010 330 Grails 1.3 観察
PDF
Oscon Java Testing on the Fast Lane
PDF
Grails Launchpad - From Ground Zero to Orbit
PPTX
Groovy grails types, operators, objects
PDF
GR8Conf 2009: What's New in Groovy 1.6? by Guillaume Laforge
PPTX
Metaprogramming Techniques In Groovy And Grails
PDF
Groovy, to Infinity and Beyond - Groovy/Grails eXchange 2009
PDF
Groovy to infinity and beyond - GR8Conf Europe 2010 - Guillaume Laforge
PPT
Introduction To Grails
PDF
Greach - The Groovy Ecosystem
PDF
Ast transformations
PDF
Grails 1.2 探検隊 -新たな聖杯をもとめて・・・-
PDF
Grooscript in Action SpringOne2gx 2015
PDF
UContracts a DSL to document and validate structural requirements of frameworks
Groovy 2 and beyond
Lift off with Groovy 2 at JavaOne 2013
Groovy 2.0 webinar
Groovy: to Infinity and Beyond -- JavaOne 2010 -- Guillaume Laforge
Apache Groovy's Metaprogramming Options and You
Groovy.pptx
Jggug 2010 330 Grails 1.3 観察
Oscon Java Testing on the Fast Lane
Grails Launchpad - From Ground Zero to Orbit
Groovy grails types, operators, objects
GR8Conf 2009: What's New in Groovy 1.6? by Guillaume Laforge
Metaprogramming Techniques In Groovy And Grails
Groovy, to Infinity and Beyond - Groovy/Grails eXchange 2009
Groovy to infinity and beyond - GR8Conf Europe 2010 - Guillaume Laforge
Introduction To Grails
Greach - The Groovy Ecosystem
Ast transformations
Grails 1.2 探検隊 -新たな聖杯をもとめて・・・-
Grooscript in Action SpringOne2gx 2015
UContracts a DSL to document and validate structural requirements of frameworks

More from GR8Conf (20)

PDF
DevOps Enabling Your Team
PDF
Creating and testing REST contracts with Accurest Gradle
PDF
Mum, I want to be a Groovy full-stack developer
PDF
Metaprogramming with Groovy
PDF
Scraping with Geb
PDF
How to create a conference android app with Groovy and Android
PDF
Cut your Grails application to pieces - build feature plugins
PDF
Performance tuning Grails applications
PDF
Ratpack and Grails 3
PDF
Grails & DevOps: continuous integration and delivery in the cloud
PDF
Functional testing your Grails app with GEB
PDF
Deploying, Scaling, and Running Grails on AWS and VPC
PDF
The Grails introduction workshop
PDF
Idiomatic spock
PDF
The Groovy Ecosystem Revisited
PDF
Groovy 3 and the new Groovy Meta Object Protocol in examples
PDF
Integration using Apache Camel and Groovy
PDF
CRaSH the shell for the Java Virtual Machine
PDF
Grooscript gr8conf
PDF
CRaSH the shell for the Java Virtual Machine
DevOps Enabling Your Team
Creating and testing REST contracts with Accurest Gradle
Mum, I want to be a Groovy full-stack developer
Metaprogramming with Groovy
Scraping with Geb
How to create a conference android app with Groovy and Android
Cut your Grails application to pieces - build feature plugins
Performance tuning Grails applications
Ratpack and Grails 3
Grails & DevOps: continuous integration and delivery in the cloud
Functional testing your Grails app with GEB
Deploying, Scaling, and Running Grails on AWS and VPC
The Grails introduction workshop
Idiomatic spock
The Groovy Ecosystem Revisited
Groovy 3 and the new Groovy Meta Object Protocol in examples
Integration using Apache Camel and Groovy
CRaSH the shell for the Java Virtual Machine
Grooscript gr8conf
CRaSH the shell for the Java Virtual Machine

Recently uploaded (20)

PDF
Approach and Philosophy of On baking technology
PDF
Encapsulation theory and applications.pdf
PPTX
A Presentation on Artificial Intelligence
PDF
CIFDAQ's Market Insight: SEC Turns Pro Crypto
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PPTX
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
Machine learning based COVID-19 study performance prediction
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PPTX
MYSQL Presentation for SQL database connectivity
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Modernizing your data center with Dell and AMD
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Approach and Philosophy of On baking technology
Encapsulation theory and applications.pdf
A Presentation on Artificial Intelligence
CIFDAQ's Market Insight: SEC Turns Pro Crypto
20250228 LYD VKU AI Blended-Learning.pptx
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Understanding_Digital_Forensics_Presentation.pptx
Machine learning based COVID-19 study performance prediction
Reach Out and Touch Someone: Haptics and Empathic Computing
MYSQL Presentation for SQL database connectivity
The Rise and Fall of 3GPP – Time for a Sabbatical?
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Chapter 3 Spatial Domain Image Processing.pdf
Modernizing your data center with Dell and AMD
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Spectral efficient network and resource selection model in 5G networks
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf

GR8Conf 2011: GContracts