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=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: fac41,8ff80a74f45b5cd3,start X-Google-Attributes: gidfac41,public X-Google-Thread: 103376,8ff80a74f45b5cd3,start X-Google-Attributes: gid103376,public From: card@syr.lmco.com Subject: Visibility and access to "public" attributes Date: 1997/08/29 Message-ID: <872873007.3110@dejanews.com>#1/1 X-Deja-AN: 268945392 To: card@syr.lmco.com X-Http-User-Agent: Mozilla/3.01 (X11; U; SunOS 5.5 sun4m) X-Originating-IP-Addr: 192.91.146.34 (proxy3a.lmco.com) Organization: Deja News Posting Service X-Authenticated-Sender: card@syr.lmco.com X-Article-Creation-Date: Fri Aug 29 16:43:27 1997 GMT Newsgroups: comp.lang.ada,comp.lang.eiffel Date: 1997-08-29T00:00:00+00:00 List-Id: Earlier today, I saw an interesting discussion about the way Ada and Eiffel perform "information hiding". In Ada, a type is is either public (i.e. its attributes can be read and written by a client of the type) or private (the attributes of the type are not visible and can only be accessed using the type's public methods). In Eiffel, by contrast, a type can be "semi-private", by which I mean that its attributes can be made visible for read purposes but not write purposes. This was said to be superior to the Ada method of using a private type with access functions to get at its attributes because in Ada the access functions couldn't have the same name as the attributes, i.e. you'd need a function named "Get_X" to read the value of attribute X, while in Eiffel you could just use "X". I excerpt the following from Don Harrison's post: >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; First of all, let me say that in Ada the closest analogue to an Eiffel/C++ style class (one in which the unit of modularity is the same as the type) is a tagged type and its dispatching operations. In Ada, it is certainly possible to have access functions which have the same names as the attributes of their tagged type. The following is some compilable Ada code that illustrates this: package Test1 is type My_Type is tagged private; -- attributes invisible function A(Obj : My_Type) return Boolean; -- access function private type My_Type is tagged record A : Boolean; -- attribute end record; end Test1; package body Test1 is function A(Obj : My_Type) return Boolean is begin return Obj.A; end A; end Test1; Thus, there is no restriction in Ada that prevents an access function from having the same name as a class' (tagged type's) attribute. That said, I think it is fair to say that I believe the idea behind Ada's "all or nothing" approach is that you may want to ensure that a client never depends on some of a type's attributes. For instance, you might have an Aircraft class with a Take_Off method. Should a client be able to view (and thus potentially depend upon) attributes in the Aircraft type that might change but would not impact the interface to Take_Off? I know that Eiffel can totally hide the attributes of an object (i.e. accessed via methods only) as well. When writing Eiffel programs, how do you decide when to make a type's attributes "read-only visible" and when to hide them? - Mike --------------- Michael P. Card Lockheed Martin Ocean, Radar and Sensor Systems Division Syracuse, NY 13221 voice: (315)-456-3022 FAX: (315)-456-2414 e-mail:card@syr.lmco.com -------------------==== Posted via Deja News ====----------------------- http://www.dejanews.com/ Search, Read, Post to Usenet