com.mcdermottroe.exemplar
Class DBC

java.lang.Object
  extended by com.mcdermottroe.exemplar.DBC

public final class DBC
extends Object

Provide some rudimentary Design By Contract™ facilities. This class attempts to mimic the Design By Contract™ mechanisms present in Eiffel. It would be nice to have invariants as well, but that would require more language support. If only Java™ had Design By Contract™ built in or if Eiffel didn't have hideous syntax!

Since:
0.1
See Also:
Meyer, Bertrand. 1997. Object Oriented Software Construction, 2nd Edition. Prentice-Hall.

Constructor Summary
private DBC()
          Prevent this class from being externally instantiated.
 
Method Summary
static void ASSERT(boolean assertion)
          An assertion mechanism which does more than the assert keyword found in Java version 1.4 and later.
static void ENSURE(boolean postcondition)
          Alias of ASSERT(boolean) for describing a postcondition for a method.
static void IGNORED_EXCEPTION(Throwable t)
          A marker for an ignored exception.
static void REQUIRE(boolean precondition)
          Alias of ASSERT(boolean) for describing a precondition for a method.
static void UNREACHABLE_CODE()
          A marker for unreachable code.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DBC

private DBC()
Prevent this class from being externally instantiated.

Method Detail

ASSERT

public static void ASSERT(boolean assertion)
An assertion mechanism which does more than the assert keyword found in Java version 1.4 and later. This assertion mechanism includes information on where the assertion was thrown from.

Parameters:
assertion - The boolean expression which should be true.
See Also:
Options.isDebugSet()

REQUIRE

public static void REQUIRE(boolean precondition)
Alias of ASSERT(boolean) for describing a precondition for a method.

Parameters:
precondition - The condition which must be true at the start of a routine.
See Also:
ASSERT(boolean)

ENSURE

public static void ENSURE(boolean postcondition)
Alias of ASSERT(boolean) for describing a postcondition for a method.

Parameters:
postcondition - The condition which must be true at the end of a routine.
See Also:
ASSERT(boolean)

UNREACHABLE_CODE

public static void UNREACHABLE_CODE()
A marker for unreachable code. This should be used in cases where the programmer believes that it is impossible to reach and hence does not require more elaborate error reporting. An example of such would be in the default case of a switch statement switching on an enumerated type.

See Also:
ASSERT(boolean)

IGNORED_EXCEPTION

public static void IGNORED_EXCEPTION(Throwable t)
A marker for an ignored exception. To be used in cases where the programmer is forced to catch an exception but wishes to continue processing anyway.

Parameters:
t - The exception to be ignored.