Re: Criteria to decide what is private?



"Daniel T." wrote:

Miguel Oliveira e Silva <mos@xxxxxxxxx> wrote:

The invariant is exposed is when - as you correctly put
it - it is the clients responsibility to ensure it:
meaning when there exists a public writable attribute.

Lets take a look to a simple example (Eiffel syntax):

class PERSON

public

age: INTEGER; -- in Eiffel public attributes can only be used a
"rvalues"

set_age(a: INTEGER) is
require -- precondition
non_negative_age: a >= 0
do
age := a
ensure -- postcondition
age = a
end;

invariant

age >= 0

end -- PERSON

I'm somewhat confused about this point. Is your PERSON class an example
of an invariant being exposed or not?

No. The invariant is correctly protected by the class itself.

The comment above the code implies to me that it is.

(Sorry.)

The invariant is exposed to clients (which I'm reading as
possibly being compromised by clients) if the class has
public writable attributes (which are not possible in Eiffel,
but quite common in C++ and Java).

Even when the supplier has a missing precondition
in the specification (and implementation) of its class,
the invariant is not exposed, because is still the supplier
fault for not having a correct specification of its class.

-miguel

--
Miguel Oliveira e Silva
DETI-IEETA, Universidade de Aveiro, PORTUGAL


.



Relevant Pages

  • Re: Tell, Dont Ask
    ... about the responsibilities of external clients, ... The whole point was for Range to ensure its own invariant. ... The context simply ... enforces an invariant and How it is enforced. ...
    (comp.object)
  • Re: Tell, Dont Ask
    ... about the responsibilities of external clients, ... The whole point was for Range to ensure its own invariant. ... The context simply ... enforces an invariant and How it is enforced. ...
    (comp.object)
  • Re: Tell, Dont Ask
    ... Thus the clients must obey the invariant in their ... that is manifested by the setHigh and setLow interface methods. ... of Range to manage it's invariant, not the clients. ... where the *preconditions are the same as the invariant*. ...
    (comp.object)
  • Public attributes and invariants (was: Unit Testing and Test Cases)
    ... Chris Dollin wrote: ... local module problem if, and only if, there are no ... is helpless to ensure their part on the invariant. ... It is the object itself, not its clients, ...
    (comp.software.testing)
  • Re: data calculated in form field not showing up on table datasheet
    ... I have a Clients form that I fill out, and it puts the information in my ... calculated a client's age from data in a Date of Birth field and Admission ... here is my code that is in the Control Source property of the Age At ...
    (microsoft.public.access.forms)