Think about the opposite case: uninitialized objects.
Q: How many times will this loop repeat?
1 2 3 4 5
|
int x; // uninitialized
while ( 7 < x ) {
// fubar
--x;
}
|
A: Nobody knows. The value of x is undefined.
Q: Ahh, but int is not class. Surely a class:
1 2 3 4 5
|
struct Point {
int x; int y;
};
Point bar; // Where is it?
|
A: Should it really do more work by default than the int does?
Q: One more time:
1 2 3 4 5
|
class Circle {
Point pos;
float r;
float area; // cached value, must always == r*r*pi()
};
|
The area is computed from r. One could always recompute it, but this time memory is cheaper. However, the area must be updated whenever the r changes, including on creation of a circle.
In other words, all objects (including ints and chars) should always (or at least before they are used) have a
known and consistent state. How would you feel about receiving a wallet full of $1000 bills that tells that it has only 42 cents in it? Inconsistent, incoherent.