Class Invariant

In computer programming, specifically object-oriented programming, a class invariant is an invariant used to constrain objects of a class. Methods of the class should preserve the invariant. The class invariant constrains the state stored in the object.

Class invariants are established during construction and constantly maintained between calls to public methods. Temporary breaking of class invariance between private method calls is possible, although not encouraged.

An object invariant, or representation invariant, is a programming construct consisting of a set of invariant properties that remain uncompromised regardless of the state of the object. This ensures that the object will always meet predefined conditions, and that methods may, therefore, always reference the object without the risk of making inaccurate presumptions. Defining class invariants can help programmers and testers to catch more bugs during software testing.

Read more about Class Invariant:  Class Invariants and Inheritance

Famous quotes containing the word class:

    The enemy are no match for us in a fair fight.... The young men ... of the upper class are kind-hearted, good-natured fellows, who are unfit as possible for the business they are in. They have courage but no endurance, enterprise, or energy. The lower class are cowardly, cunning, and lazy. The height of their ambition is to shoot a Yankee from some place of safety.
    Rutherford Birchard Hayes (1822–1893)