1 / 15

Design by Contract using Jose

Design by Contract using Jose. Ohad Barzilay April 2004, IDC. About Jose. A Design by Contract tool written for java Still in ALFA status Similar tools: iContract JContract JMSAssert JML. More About Jose. Uses AspectJ Uses Doclet Uses ANTLR. Getting Jose.

onella
Download Presentation

Design by Contract using Jose

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Design by Contractusing Jose Ohad Barzilay April 2004, IDC

  2. About Jose • A Design by Contract tool written for java • Still in ALFA status • Similar tools: • iContract • JContract • JMSAssert • JML

  3. More About Jose • Uses AspectJ • Uses Doclet • Uses ANTLR

  4. Getting Jose • For the use of this course students only and only for academic purposes • Command line configuration or as an IDE external tool • Executable jar • Get it this weekend from the course discussion group

  5. Stack with Assertions (1) class STACK1 [G] feature -- Access count: INTEGER -- Number of stack elements item: G is -- Top element require not empty do ... end

  6. Stack with Assertions (1) publicclassStack1 { publicintcount() { returnelements.size(); } /** *@require!empty(),"NotEmpty" */ publicObjectitem() { returnelements.firstElement(); } protectedVectorelements=null; }

  7. Stack with Assertions (2) feature -- Status report empty: BOOLEAN is -- Is stack empty? do ...end full: BOOLEAN is -- Is stack representation full? do ...end

  8. Stack with Assertions (2) publicbooleanempty() { returncount()==0; } publicbooleanfull() { returnelements.capacity()==count(); }

  9. Stack with Assertions (3) feature -- Element change put (x: G) is -- Add x on top. require not full do ... ensure not empty item = x count = old count + 1 end

  10. Stack with Assertions (3) /** *@require!full(),"NotFull" *@ensure!empty(),"NotEmpty" *@ensureitem()==x,"item()equalsx" *@ensurecount()==$prev(count())+1, *"count()incremented" */ publicvoidput(Objectx) { elements.add(0,x); }

  11. Stack with Assertions (4) remove is -- Remove top element. require not empty do ... ensure not full count = old count – 1 end end

  12. Stack with Assertions (4) /** *@require!empty(),"NotEmpty" *@ensure!full(),"NotFull" *@ensurecount()==$prev(count())-1, * "count()decremented" */ publicvoidremove() { elements.remove(0); }

  13. Class level Assertions (5) /** *@invariantelements.size()>=0, * "nonnegativesize" */ publicclassStack1 { ... }

  14. Jose keywords • Precondition • @precondition • @pre • @ require • Postcondition • @ postcondition • @ post • @ ensure • Invarinat • @ invarinat • @ inv

  15. Jose keywords • Return value • $ret • Old value • $prev(<expr>) • $prev(<type>;<expr>)

More Related