A question about DbC

bearophile bearophileHUGS at lycos.com
Sat Oct 9 19:18:39 PDT 2010


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


More information about the Digitalmars-d-learn mailing list