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.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,fa22a73e140a6fd1 X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,UTF8 Received: by 10.68.135.231 with SMTP id pv7mr16824406pbb.8.1328703832287; Wed, 08 Feb 2012 04:23:52 -0800 (PST) Path: wr5ni1133pbc.0!nntp.google.com!news1.google.com!eweka.nl!lightspeed.eweka.nl!194.109.133.85.MISMATCH!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!news.stack.nl!aioe.org!.POSTED!not-for-mail From: =?utf-8?Q?Yannick_Duch=C3=AAne_=28Hibou57?= =?utf-8?Q?=29?= Newsgroups: comp.lang.ada Subject: Re: Object-Oriented style question Date: Wed, 08 Feb 2012 13:23:50 +0100 Organization: Ada @ Home Message-ID: References: <4f098fcb$0$6577$9b4e6d93@newsspool3.arcor-online.net> NNTP-Posting-Host: Nct6a+O2WWeAxakAlXSC1w.user.speranza.aioe.org Mime-Version: 1.0 X-Complaints-To: abuse@aioe.org User-Agent: Opera Mail/11.61 (Linux) X-Notice: Filtered by postfilter v. 0.8.2 Content-Type: text/plain; charset=utf-8; format=flowed; delsp=yes Content-Transfer-Encoding: Quoted-Printable Date: 2012-02-08T13:23:50+01:00 List-Id: Le Sun, 08 Jan 2012 13:45:00 +0100, Georg Bauhaus = a =C3=A9crit: > Given a tagged O-O type T in package Pak and a "method" of T, > called "Info". Method Info queries the state of its parameter, > which is of type T. States are of a type named "Value", which > also happens to be defined in Pak. > [=E2=80=A6] > My question is about the best way to declare the Info operation, > and its parameter profile in particular. > [=E2=80=A6] > type Value is range 1000 .. 1003; > > type T is abstract tagged private; > > function Info (Item : in T) return Value; > function Info_1 (Item_Doubly_Indirect : access T) return Value; > function Info_2 (Item_Doubly_Indirect : access constant T) return = = > Value; > function Info_3 (Item_Doubly_Indirect : not null access constant T= ) = > return Value; > [=E2=80=A6] > Info_2 is still close to the meaning of a query function except > that the parameter may be null. This then means that there is *no* > object of type T'Class and, consequently, there cannot be a state! > Programs that call Info_2 could then needlessly raise an exception. > (If "null" is somehow important in a set of objects from > the T hierarchy, this does not preclude testing for "null", > since the test can be performed at the place in the program > where both the null pointer and the test are needed (and a default > state value assigned).) Yes, but with the need to repeat the test at every call place. This woul= d = also mean possibly different interpretation at each call place. If = multiple interpretation are intended, that's OK, otherwise, this would b= e = error=E2=80=91prone (and redundant with no added value). On the other hand, giving Null a meaning in the sense of the meaning = associated with an instance of a type, is a bad idea (ambiguous and lack= s = evidence from the reader's point of view), and a special state or value = of = the type is better. For the above reasons, I would exclude both Info_1 and Info_2. Now, as you noted Info_3 fall into the same as Info, leaving a single = question: why use an access type ? As T is a private record type, if it = = needs access type for sharing, this could be encapsulated, and Info_3 ma= y = be dropped in favor of Info. From my point of view, the classical way to do with Info, is also the b= est = of the above four. -- = =E2=80=9CSyntactic sugar causes cancer of the semi-colons.=E2=80=9D [1] =E2=80=9CStructured Programming supports the law of the excluded muddle.= =E2=80=9D [1] [1]: Epigrams on Programming =E2=80=94 Alan J. =E2=80=94 P. Yale Univers= ity