Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Spring Framework | Web Services | BioInformatics | Java Server Faces | Jboss 3.0 tutorial | Hibernate 3.0 | XML

Tutorial Categories: Ajax | Articles | JSP | Bioinformatics | Database | Free Books | Hibernate | J2EE | J2ME | Java | JavaScript | JDBC | JMS | Linux | MS Technology | PHP | RMI | Web-Services | Servlets | Struts | UML


Java Tutorials



Struts Tutorials

Struts Resources

Visit Forum! Post Questions!
Jobs At RoseIndia.net!

Java: Design By Contract

Bertrand Meyer formalized a programming methodology called Design by Contract, which has become popular in some groups. In addition to specifying programming code to carry out the operations of a function (method), the programmer also specifies:

  • Preconditions - assumptions the function makes. These are usually expressed as statements that must be true about the parameters. This is the part of the "contract" that the caller must agree to.
  • Postconditions - conditions that are true when it finishes. These conditions define the responsibilities of the function, and are the part of the contract that the function agrees to.
  • Invariants - conditions that should be true of a class in general (class invariants. It's sometimes applied to loops (loop invariants). These seem to be generally less useful than pre- and postconditions.

Design benefits

The strength of this programming methodology is that it gets the programmer to think clearly about what a function does, and it provides documentation for the caller.

Programming language support for Design by Contract

A few programming languages, eg Eiffel and Sather (Sather home page), implement pre- and postconditions in executable code so that they are checked at run time. Most programming language don't have such support, so programmers who want to use pre- and postconditions often write comments documenting the conditions. This is not an ideal situation because the comments aren't verified automatically, and they may not even be consistent with the actual code.


Perhaps the closest one can come in pure Java to implementing pre- and postconditions is to use the assert statement. See Assertions.


It seems that Bertrand Meyer's company, Interactive Software Engineering, has trademarked the phrase "Design by Contract".

Further reading

Building bug-free O-O software: An introduction to Design by Contract

Ask programming questions?



Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 

Current Comments

0 comments so far (post your own) View All Comments Latest 10 Comments:
  JDO Tutorials
  EAI Articles
  Struts Tutorials
  Java Tutorials
  Java Certification

Tell A Friend
Your Friend Name


Browse all Java Tutorials
Java JSP Struts Servlets Hibernate XML
Ajax JDBC EJB MySQL JavaScript JSF
Maven2 Tutorial JEE5 Tutorial Java Threading Tutorial Photoshop Tutorials Linux Technology
Technology Revolutions Eclipse Spring Tutorial Bioinformatics Tutorials Tools SQL

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright 2007. All rights reserved.

[an error occurred while processing this directive]