Invariant
- description: a set of assertions that must always hold true during the life of an object for the program to be valid.
- eg An example of invariant could be that exactly one of two member variables should be null. Or that if one has a given value, then the set of allowed values for the other is this or that...
- c.pattern (Private) I sometime use a member function of the object to check that the invariant holds. If this is not the case, an assert is raised. And the method is called at the start and exit of each method that changes the object (in C++, this is only one line...)
Resources