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 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,af92cb4b0cc736af X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2002-10-31 09:18:50 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!logbridge.uoregon.edu!arclight.uoregon.edu!wn13feed!wn11feed!wn12feed!worldnet.att.net!204.127.198.203!attbi_feed3!attbi.com!sccrnsc01.POSTED!not-for-mail Message-ID: <3DC165F9.9000000@attbi.com> From: "Robert I. Eachus" User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.0.1) Gecko/20020823 Netscape/7.0 X-Accept-Language: en-us, en MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: problem with abstract types References: <3DC12CFF.EC36842C@brighton.ac.uk> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit NNTP-Posting-Host: 24.61.239.24 X-Complaints-To: abuse@attbi.com X-Trace: sccrnsc01 1036084730 24.61.239.24 (Thu, 31 Oct 2002 17:18:50 GMT) NNTP-Posting-Date: Thu, 31 Oct 2002 17:18:50 GMT Organization: AT&T Broadband Date: Thu, 31 Oct 2002 17:18:50 GMT Xref: archiver1.google.com comp.lang.ada:30262 Date: 2002-10-31T17:18:50+00:00 List-Id: Ulrich Eckhardt wrote: > No. openRegistry is first defined abstract and then implemented > as openRegistry(reg : in out file_registry; ..) and > openRegistry(reg : in out win_registry; ..) . Error, C++ thinking detected. In Ada, unless you really have use them for some reason, avoid access types. Access types IMHO, should be buried in packages which implement container abstractions and never show up in package specifications or user code. If you change your specification to: package registry is type registry is abstract tagged limited private; function openRegistry(Priviledge: in Sys_Access Registry_Name: String) return registry is abstract; [..] exception Registry_Error; -- if you must. end Registry; In the two (or more!) child packages: function openRegistry (a : in sys_access; p_name : String) return file_registry is --change as necessary. Reg: file_registry; begin -- any non-default actions here... return Reg; end fileRegistry; Then your test program becomes: with registry; use registry; procedure main is declare reg := openRegistry(CLASS_USER,"registrytest"); begin null; -- for now. exception when Registry_Error => -- do something useful like printing -- location. when others => -- be prepared for anything in a test program... end; exception when others => -- catch finalization bugs here. end main; Now you might think that Reg is declared inside a function and that it will either need to be declared on the heap, or copied during the return. LET THE COMPILER WORRY ABOUT ALL THAT. In practice the compiler will probably build the return value in place if it can inline openRegistry. But it is not your problem, and a lot of unnecessary code goes away. Also you will note that I got rid of any need for Unbounded_String. It may be that some of the individual implementations of openRegistry will need to use Unbounded_String, but if the name never changes, you probably won't. In any case, make things easy for the user of the abstraction. In this case it also makes it easier for the implementor.