GR8Conf 2011: GContracts

734
-1

Published on

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
734
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
0
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

GR8Conf 2011: GContracts

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

×