Boost logo

Boost :

From: Fernando Cacciola (fernando_cacciola_at_[hidden])
Date: 2003-10-29 22:06:48


"E. Gladyshev" <egladysh_at_[hidden]> escribió en el mensaje
news:20031030022640.923.qmail_at_web40811.mail.yahoo.com...
>
> --- Fernando Cacciola <fernando_cacciola_at_[hidden]> wrote:
> [...]
> > > You can imaging some examples like the following.
> > > struct type
> > > {
> > > //invariant is x + y = 10
> > > int x;
> > > int y;
> > >
> > > void f( int n )
> > > {
> > > x = n; //* invariant is broken
> > > f1(); //* is this allowed?
> > > y = 10-n; //* invariant restored
> > > }
> > >
> > The way I see it, if f1() is not public, then the above is most likely
OK.
> > If is it public, then it is most likely not OK.
>
> According to Dave (if understood him right),
> it is Ok to call not just a public method of the same type
> but any method of any type internally
> while the invariant is broken.
>
> For example it seems to be ok to do the following.
> void f( int n )
> {
> x = n; //* invariant is broken
> new some_other_type; //*** calling an outside method
> y = 10-n; //* invariant restored
> }
>
Calling an outside method doesn't affect *this* state so whether this is OK
while the invariant is broken depends on what the outsider require about
*this* invariant.
For example, if the above were

   new some_other_type(this);

then the call would be likely in the wrong place.

Invariants are realted to design *contracts* and not all calls are routing
contract messages. Implementation calls typically don't, and as you pointed
out, outside calls might be also contract unrelated, thus the invariant need
not hold during the call.

Fernando Cacciola
SciSoft


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk