HR & Training +91-769-609-5145

Home » Uncategorized » Design by Contract in Java

Design by Contract in Java

Design by Contract

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 component’s 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.

Central to DBC is the notion of an assertion — a Boolean expression about the state of a software system. At runtime we evaluate the assertions at specific checkpoints during the system’s execution. In a valid software system, all assertions evaluate to true. In other words, if any assertion evaluates to false, we consider the software system invalid or broken.

DBC’s central notion somewhat relates to the #assert macro in C and C++ programming language. However DBC takes assertions a zillion levels further.

In DBC, we identify three different kinds of expressions:

  • Preconditions
  • Postconditions
  • Invariants

Leave a Reply

Your email address will not be published. Required fields are marked *