Nice TWiki > Dev > NiceDiscussions? > ClassInvariants (r1.1) TWiki webs:
Dev | Doc | Main | TWiki | Sandbox
Dev . { Changes | Index | Search | Go }
I'm looking ahead to when invariants are added, and the crossover with NiceConstructors. Vague thoughts only, feel free to edit.

There's an Eiffel hack to allow different sets of invariants in different conditions: express your invariants as

invariant_name: condition implies [<an invariant set>]
The trouble with using this for constructors is you have to list what parts of the invariant each method really depends on in each method, which defeats the purpose of an invariant.

I wondered about a distinction between methods that preserve the invariant but don't require it, which could be freely called both within constructors and outside them, and ones that both preserve and require. Note that this is a different situation again to constructors, which do not require the invariant but guarantee to make it satisfied: a preserving-only method would not necessarily make it satisfied if it wasn't when the method was called. The problem with this arises when the preserve-only method is called directly after some buggy method has broken the invariant. The preserve-only method doesn't do the proper checking, because it's happy to accept a broken invariant at method start.

My suggestion is a general condition in_constructor which is set true at the start of each constructor and false at its end. Preserve-only methods guarantee to check the invariant

For this to work with nested constructor calls I guess constructors only set it to false at end if it was false before they set it at start, or something.

Anyway, this is entirely off-the-cuff uninformed thinking out loud, with no idea how implementation-practical the idea is.

-- SamsonDeJ - 15 May 2003

Topic ClassInvariants . { Edit | Attach | Ref-By | Printable | Diffs | r1.4 | > | r1.3 | > | r1.2 | More }
Revision r1.1 - 16 May 2003 - 00:21 GMT - SamsonDeJ
Parents: NiceDiscussions?
Copyright © 1999-2003 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback.