From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=0.2 required=5.0 tests=BAYES_00,INVALID_MSGID, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: fac41,f66d11aeda114c52 X-Google-Attributes: gidfac41,public X-Google-Thread: 103376,f66d11aeda114c52 X-Google-Attributes: gid103376,public From: nospam@thanks.com.au (Don Harrison) Subject: Re: Design By Contract Date: 1997/08/29 Message-ID: #1/1 X-Deja-AN: 268868769 Sender: news@syd.csa.com.au References: Reply-To: nospam@thanks.com.au X-Nntp-Posting-Host: dev50 Organization: CSC Australia, Sydney Newsgroups: comp.lang.ada,comp.lang.eiffel Date: 1997-08-29T00:00:00+00:00 List-Id: Jon S Anthony wrote: :In article nospam@thanks.com.au (Don Harrison) writes: : :> - Strict enforcement of encapsulation while maximising visibility. Eiffel :> offers a look-but-don't-touch view of object attributes. In Ada83, :> an attribute and its type has to be declared in the visible interface in :> order for clients to see it's structure but then they can also update it :> directly. If you declare its type as private, clients can't update it :> directly but neither can they see its structure. : :Isn't that exactly the point? Why should a client be able to see the :actual structure, aka implementation???? No, the point is that there is no need to hide the structure of an attribute so long as it's read-only (look-but-don't-touch). These semantics allow you to query components of visible objects directly: a.SOME_TYPE ... if a.y > 0 then x := a.y end but prevent you from updating them directly (which would break encapsulation): a.y := x -- Illegal [You can update them *indirectly* by calling an operation in the object: a.set_y (x)] To get similar read-only semantics in Ada, you have to declare the attribute in the package body (hiding it) and return it via an exported function (which can't have the same name): the_a: SOME_TYPE ... function a return SOME_TYPE is begin return the_a; end; I prefer the Eiffel model because: - It's simple and direct. - It doesn't clutter the spec and body with functions. - It doesn't force you to invent multiple identifiers (one of which has a contrived name: "the_a" above). IMO, the other possibilities for attributes in Ada are unattractive because they are either too permissive (look-and-touch - attributes declared in the visible part of the spec) or too restrictive (don't-look-don't touch - private attributes). BTW, someone with a sense of humour may enjoy BM's discussion of Ada private types (OOSC-2, 33.4 - Hiding the Representation: The Private Story. P.1085-1087). [...] Don. (Reverse to reply) =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- Don Harrison au.com.csa.syd@donh