Re: Criteria to decide what is private?
- From: Miguel Oliveira e Silva <mos@xxxxxxxxx>
- Date: Fri, 19 Jan 2007 16:44:56 +0000
"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
.
- References:
- Encapsulation vs Extensibility
- From: Anthony Paul
- Re: Encapsulation vs Extensibility
- From: S Perryman
- Re: Encapsulation vs Extensibility
- From: Mark Nicholls
- Criteria to decide what is private? (was: Encapsulation vs Extensibility)
- From: Daniel T.
- Re: Criteria to decide what is private? (was: Encapsulation vs Extensibility)
- From: Mark Nicholls
- Re: Criteria to decide what is private? (was: Encapsulation vs Extensibility)
- From: Daniel T.
- Re: Criteria to decide what is private? (was: Encapsulation vs Extensibility)
- From: Mark Nicholls
- Re: Criteria to decide what is private? (was: Encapsulation vs Extensibility)
- From: Daniel T.
- Re: Criteria to decide what is private? (was: Encapsulation vs Extensibility)
- From: Mark Nicholls
- Re: Criteria to decide what is private? (was: Encapsulation vs Extensibility)
- From: Daniel T.
- Re: Criteria to decide what is private? (was: Encapsulation vs Extensibility)
- From: Mark Nicholls
- Re: Criteria to decide what is private? (was: Encapsulation vs Extensibility)
- From: Daniel T.
- Re: Criteria to decide what is private?
- From: S Perryman
- Re: Criteria to decide what is private?
- From: Daniel T.
- Re: Criteria to decide what is private?
- From: S Perryman
- Re: Criteria to decide what is private?
- From: Daniel T.
- Re: Criteria to decide what is private?
- From: Miguel Oliveira e Silva
- Re: Criteria to decide what is private?
- From: Daniel T.
- Re: Criteria to decide what is private?
- From: Miguel Oliveira e Silva
- Re: Criteria to decide what is private?
- From: Daniel T.
- Encapsulation vs Extensibility
- Prev by Date: Re: Criteria to decide what is private?
- Next by Date: Re: DbC and unspecified state
- Previous by thread: Re: Criteria to decide what is private?
- Next by thread: Re: Criteria to decide what is private? [LONG]
- Index(es):
Relevant Pages
|