• Like
  • Save
GR8Conf 2011: GContracts
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

GR8Conf 2011: GContracts

  • 672 views
Published

 

Published in Technology
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
    Be the first to like this
No Downloads

Views

Total Views
672
On SlideShare
0
From Embeds
0
Number of Embeds
0

Actions

Shares
Downloads
0
Comments
0
Likes
0

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. GContractsAndre Steingress @sternegross/@gcontracts
  • 2. LINZ, AUSTRIA
  • 3. www.ejug.at
  • 4. ABOUTGCONTRACTS.
  • 5. GCONTRACTSDESIGN BY CONTRACT (tm) FOR GROOVY Groovy 1.7+ (was 1.6 loooong time ago)BSD LICENSEhttps://github.com/andresteingress/gcontracts
  • 6. JUMP START.
  • 7. LET‘S REVIEW THIS ACCOUNT CLASS.Googled, found at javacoffeebreak.com
  • 8. PREREQUISITES.
  • 9. @Grab( group=org.gcontracts, module=gcontracts-core, version=[1.2.3,)) no additional dependencies...
  • 10. import org.gcontracts.annotations.*
  • 11. 3 ANNOTATIONS.
  • 12. Commonalities• special assertion types • specifying boolean expressions• closure instances as annotation parameters @MyAnnotation({ param?.size() > 0 })
  • 13. @Requires• precondition• a method‘s bouncer
  • 14. @Ensures• postcondition• a method‘s mother
  • 15. @Invariant• class-invariant• an object‘s god.
  • 16. LET‘S REVIEW THIS ACCOUNT CLASS.Googled, found at javacoffeebreak.com
  • 17. INTERNALS.
  • 18. @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)
  • 19. 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()
  • 20. Officially Supported since Groovy 1.8!
  • 21. Works since Groovy 1.6http://pniederw.wordpress.com/2010/03/04/3/
  • 22. MORE FEATURES.
  • 23. LABELING
  • 24. INTERFACE CONTRACTS
  • 25. INTERFACE CONTRACTS
  • 26. INHERITANCE✓INTERFACE CONTRACTS✓ABSTRACT CLASSES✓CONCRETE CLASSES✓MIXED
  • 27. INHERITANCE✓ACROSS COMPILATION UNITS
  • 28. MICRO CONTRACTS REUSABLE CONTRACT PART
  • 29. MICRO CONTRACTS
  • 30. Grails Integration• Container extends object construction time• @Service stereotype causes CI validation in @PostConstruct
  • 31. GroovyDoc Integration
  • 32. https://github.com/andresteingress/gcontracts/wiki
  • 33. ABOUTCONTRACTS.
  • 34. MR.„DESIGN BY CONTRACT“
  • 35. WHY CONTRACTS?
  • 36. SPOCK, JUNIT, et. al. ARE„THE CHINAMAN ISNOT THE ISSUE HERE, DUDE.“
  • 37. External API Changes New Programmers Changing Requirements Assumptions Additional Libraries New Use-Cases More Clients New Knowledge Code Conventions
  • 38. External API Changes New Programmers Changing Requirements Assumptions Additional Libraries New Use-Cases More Clients New Knowledge Code Conventions
  • 39. WHAT DID YOU PROGRAM LAST WEEK?CAN YOU RECALL YOUR THOUGHTS, MODELS?WHY SHOULD ANYONE ELSE KNOW ABOUT THEM?
  • 40. BUILD YOUR PLAYGROUND.
  • 41. http://about.me/asteingress
  • 42. Thank you!
  • 43. "Design by Contract" is a trademark of Interactive Software Engineering.