Recommended: Sing it, brah! 5 fabulous songs for developers
JW's Top 5
Optimize with a SATA RAID Storage Solution
Range of capacities as low as $1250 per TB. Ideal if you currently rely on servers/disks/JBODs
Page 2 of 5
When looking at contractual responsibilities, the client must satisfy the precondition prior to invoking a method. The supplier must satisfy the postcondition and class invariant. This clarifies the functionality provided and establishes an enforceable contract between a client and a supplier. Consequently, when a contract breaks (a software bug exists), you can easily tell whether the client or supplier did not satisfy its assertion(s). Also important to understand, DBC assertions are not part of the implementation. Rather, they are part of a class or interface specification. DBC clearly separates specification (what) from implementation (how). You can find additional information on DBC in Resources.
As software grows larger and more complex, the need to identify architectures and designs that satisfy such requirements as scalability, availability, security, and so on proves more important to the software's overall success. On large software projects, a team of software architects and software designers commonly specify an API for a subsystem and subsequently hand it off to a developer team to implement. The API specification is often ambiguous; in some cases, the architect or designer may interpret the specification differently than the implementer, which may introduce defects. Since DBC is assertions-based, it can help in these situations. Additionally, DBC possesses the following advantages:
As described above, DBC and assertions are not part of the implementation. Rather, they are part of a class or interface specification.
How can we isolate DBC and assertions from the implementation in Java? Here's an example of how we might apply assertions
in Java: Suppose method m(x) asserts that x is never null. In Java, the code may form:
void m(Object x)
{
assert(x != null);
}
In the above example, the assertion is part of the implementation; instead it should be part of the specification. In other words, the above example should form:
assert(x != null)
void m(Object x)
{
}
or
void m(Object x)
assert(x != null)
{
}
However, neither form will compile in Java. To effectively utilize DBC in Java, we must find an alternative mechanism, possibly
Java's /** */ comment syntax. The special comments /** */ are most commonly used in front of class and method declarations. If you placed assertions inside these special comments,
the Java compiler javac would ignore them.