3 ms·
> What if you call a public member function from inside the object? Did you re-enter? It's best to program as if every call to a public function is from client
by layer8 4y ago
> What if you call a public member function from inside the object? Did you re-enter?
It's best to program as if every call to a public function is from client code (i.e. has the same pre/postconditions/invariants). If you need different semantics, it's straightforward to forward to a private or protected function to distinguish the two cases. This is similar to the Non-Virtual Interface (NVI) pattern.
- Animats 4y agoWhen did you leave the object? There should be a check of the invariant as control leaves the object. At what moment does this happen. The F# people struggled with this. In proof systems, you check invariants at exit, and get to assume them true at entrance. So you need to be very clear about entrance and exit.
- layer8 4y agoWhenever you return from a public member function. You might wish for more flexibility, but it's a simple rule that's not difficult to work with.