Invariants (keyword)

From The Oxygene Language Wiki

Jump to:navigation, search

This is a Language topic
Feel free to add your notes to this topic below.



Invariants form part of Delphi Prism's Class Contracts feature.

In contrast to pre and post conditions, invariants are used to define a fixed state the object must fulfill at any given time. Invariants can be public or private, depending on how often their content is verified. Public invariants will be checked at the end of every public method (after the method's "ensure" block, if present, has been checked), and if an invariant fails, an exception is raised.

Private invariants will be checked at the end of every method call, public or private. Example:

type
  MyClass = class
  public
    //some methods and/or properties
  public invariants
    fField1 > 35;
    SomeProperty = 0;
    SomeBoolMethod() and not (fField2 = 5);
  private invariants
    fField > 0;
  end;

Note:

See Also


Oxygene-48.png

Area: Oxygene Language
Compiler version: Oxygene 5

Language GlossaryKeywordsTypesFAQHow To

Navigation
Areas
More
Toolbox