Jonathan M Davis:

> Yes, the problem creeps in because public methods are not necessarily the 
> only 
> way to alter the state of an object. Running the invariant before the 
> function 
> is run is actually a good catch on Walter's part. I wouldn't have thought of 
> it 
> precisely because it wouldn't be necessary if the only way to alter an object 
> is 
> through it's public methods (and that's often how classe/structs are written).

Partially unrelated: if a method is const, it doesn't change instance state, so 
there's no need to test the invariant after the method call... well 
unfortunately this is not true, because the invariant tests the static 
attributes too, that a const method may modify.

Regarding the static state, in another implementation of DbC I have seen the 
"class static invariant" too, that tests the static class attributes, but I 
don't understand why it may be useful...

Bye,
bearophile

Reply via email to