IT SOLUTIONS
Your full service technology partner! 
-Collapse +Expand
To/From Code
-Collapse +Expand Cross Ref Guide
-Collapse +Expand Members-Only
Sign in to see member-only pages.
   ► KBTo/From GuidesVB.Net  Print This     

Code Contract (VB.Net and Delphi Prism Cross Reference Guide)

By Mike Prestwood

VB.Net versus Delphi Prism: A side by side comparison between VB.Net and Delphi Prism.

 
OOP Details
 

More object oriented (OO) stuff.

Code Contract

[Other Languages] 

A.k.a. Class Contract and Design by Contracts.

A contract with a method that must be true upon calling (pre) or exiting (post). A pre-condition contract must be true when the method is called. A post-condition contract must be true when exiting. If either are not true, an error is raised. For example, you can use code contracts to check for the validity of input parameters, and results

An invariant is also a code contract which validates the state of the object required by the method.

VB.Net:  "Code Contracts" Not Supported

Although not currently supported, there are plans for the next version of VS.Net and .Net using Requires and Ensures keywords. Look for code contracts in VS.Net 2010 and .Net 4.

If you code with VS.Net 2008 Pro or above and wish to implement contracts now, checkout the following download:

Delphi Prism:  "Class Contracts" require, ensure

Prism supports class contracts with its require and ensure keywords. The require keyword is a pre condition that must be true when the method is called. The ensure keyword is a post condition that must be true when a method exits. With either, if the condition evaluates to false, then an assertion is generated.

The require and ensure keywords will expand the method body to list the preconditions; both sections can contain a list of Boolean statements, separated by semicolons.

Syntax Example:
method Cyborg.Walk(pPace);
require
pPace > 0;
  pPace < 100;
begin
ensure
FEnergyLevel >= 10;
end;












Sales Website: www.prestwood.com Or visit our legacy sales site: 
legacy.prestwood.com


©1995-2025 Prestwood IT Solutions.   [Security & Privacy]