Design by Contract                               Jiří Kiml,                               18/08/2011, Bernwww.querity.cz
Agenda            ►Motivation            ►DBC            ►Support in JAVA            ►Eclipse examples            ►Summary...
Motivation       Always code as if the guy who ends up maintaining       your code will be a violent psychopath who knows ...
Design by Contract (1)      ►The Design by Contract (DBC) software       development technique ensures high-       quality...
Design by Contract (2)   ►Central to DBC is the notion of an assertion   ►At runtime we evaluate the assertions at    spec...
Kinds of Assert expressions      ►Preconditions      ►Postconditions      ►Invariantswww.querity.cz
Preconditions ►Preconditions specify conditions that  must hold before a method can execute.  As such, they are evaluated ...
Postconditions   ►In contrast, postconditions specify    conditions that must hold after a method    completes. Consequent...
Invariants   ►An invariant specifies a condition that    must hold any time a client could invoke    an objects method. In...
Support in JAVA   ►Assert keyword   ►Many third party solutions    (annotations, AspectJ)   ►DBC classwww.querity.cz
Eclipse examples   ► XXXXwww.querity.cz
Summary     ►Contracts in code are good     ►Easy to use     ►Correctness     ►Robustnesswww.querity.cz
Links    ►Two presentations:      – http://www.eiffel.com/developers/presentations/    ►http://en.wikipedia.org/wiki/Desig...
Questions …    … and maybe answerswww.querity.cz
Thank you                        Jiří Kiml ,                        18/08/2011, Bernwww.querity.cz
Upcoming SlideShare
Loading in …5
×

Design by contract

724 views

Published on

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

No Downloads
Views
Total views
724
On SlideShare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
18
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Design by contract

  1. 1. Design by Contract Jiří Kiml, 18/08/2011, Bernwww.querity.cz
  2. 2. Agenda ►Motivation ►DBC ►Support in JAVA ►Eclipse examples ►Summary ►Linkswww.querity.cz
  3. 3. Motivation Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live. ~Martin Golding ►Wouldnt it be nice if all Java classes that you use, including your own, lived up to their promises?www.querity.cz
  4. 4. Design by Contract (1) ►The Design by Contract (DBC) software development technique ensures high- quality software by guaranteeing that every component of a system lives up to its expectations. As a developer using DBC, you specify component contracts as part of the components interface. The contract specifies what that component expects of clients and what clients can expect of it. ►Bertrand Meyer developed DBC as part of his Eiffel programming language. Regardless of its origin, DBC is a valuable design technique for all programming languages, including Java.www.querity.cz
  5. 5. Design by Contract (2) ►Central to DBC is the notion of an assertion ►At runtime we evaluate the assertions at specific checkpoints during the systems execution.www.querity.cz
  6. 6. Kinds of Assert expressions ►Preconditions ►Postconditions ►Invariantswww.querity.cz
  7. 7. Preconditions ►Preconditions specify conditions that must hold before a method can execute. As such, they are evaluated just before a method executes. Preconditions involve the system state and the arguments passed into the method. ►Preconditions specify obligations that a client of a software component must meet before it may invoke a particular method of the component. ►If a precondition fails, a bug is in a software components client.www.querity.cz
  8. 8. Postconditions ►In contrast, postconditions specify conditions that must hold after a method completes. Consequently, postconditions are executed after a method completes. Postconditions involve the old system state, the new system state, the method arguments, and the methods return value. ►Postconditions specify guarantees that a software component makes to its clients. If a postcondition is violated, the software component has a bug.www.querity.cz
  9. 9. Invariants ►An invariant specifies a condition that must hold any time a client could invoke an objects method. Invariants are defined as part of a class definition. In practice, invariants are evaluated any time before and after a method on any class instance executes. A violation of an invariant may indicate a bug in either the client or the software component.www.querity.cz
  10. 10. Support in JAVA ►Assert keyword ►Many third party solutions (annotations, AspectJ) ►DBC classwww.querity.cz
  11. 11. Eclipse examples ► XXXXwww.querity.cz
  12. 12. Summary ►Contracts in code are good ►Easy to use ►Correctness ►Robustnesswww.querity.cz
  13. 13. Links ►Two presentations: – http://www.eiffel.com/developers/presentations/ ►http://en.wikipedia.org/wiki/Design_by_con tractwww.querity.cz
  14. 14. Questions … … and maybe answerswww.querity.cz
  15. 15. Thank you Jiří Kiml , 18/08/2011, Bernwww.querity.cz

×