Ich freue mich über ein Vertragsdesign für eine Java-Bibliothek, was ich in Bezug auf die Schnittstelle bisher gemacht habe.Design by Contract-Bibliothek (Schnittstelle) Gedanken?
Der Benutzer könnte executeContract aufrufen und executeContract ruft invokeContract nach dem Aufruf von 'require' auf. ensure wird nach executeContract aufgerufen, um die Korrektheit dessen zu gewährleisten, was von invokeContract zurückgegeben wird.
Dieser Code funktioniert auch als Callback-Methode (anonymer innerer Klassenaufruf).
Was sind Ihre Gedanken? Ist dieses Design vertraglich ?, das hilft mir bisher testbaren Java-Code zu schreiben.
public interface IContractHandler {
/**
* Execute contract will invoke the #invokeContract method. In the execute method,
* check for the validity of the preconditions and the post conditions.
*
* The precondition can be null.
*
* @param precondInput - Precondition Input Data, can be null.
* @return Post condition output
*/
public Object executeContract(final Object precondInput) throws ContractError;
/**
* Require that the preconditions are met.
*/
public Object require(final Object precondInput) throws ContractError;
/**
* Ensure that the postconditions are met.
*/
public Object ensure(final Object precondInput) throws ContractError;
/**
* The precondition can be null if the contract allows for that.
*
* @param precondInput - Precondition Input Data, can be null.
* @return Post condition output
*/
public Object invokeContract(final Object precondInput) throws ContractError;
}