To give an easy example: When you model a triangle, you want to make sure that the sum of the angles always adds up to 180 degrees.
class Triangle {
number angle1, angle2, angle3;
}
This is the invariant (a condition that is supposed to be always true):
degrees (angle1 + angle2 + angle3) = degrees 180
Now the second question makes sense: since a constructor must make sure not to construct an object where the invariant doesn't hold.
The third question, then, asks if there are operations that could invalidate the invariant. For example:
void setAngle1(number whatever) { angle1 = whatever; }
And here it turns out that the design above is not good. Why? Becasue there are redundant information. A better design would be this:
class Triangle {
number angle1, angle2; // two angles
number side; // and the connecting line
}
We can always compute angle3 from angle1 and angle2. And we just need to enforce the simpler invariant that angle1 + angle2 < 180°
and side > 0