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.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no 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 11:23:00 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news.tele.dk!news.tele.dk!small.news.tele.dk!fu-berlin.de!uni-berlin.de!b8819.pppool.DE!not-for-mail From: Dmitry A.Kazakov Newsgroups: comp.lang.ada Subject: Re: problem with abstract types Date: Fri, 1 Nov 2002 09:31:20 +0100 Message-ID: References: Reply-To: mailbox@dmitry-kazakov.de NNTP-Posting-Host: b8819.pppool.de (213.7.136.25) Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7Bit X-Trace: fu-berlin.de 1036092178 4716210 213.7.136.25 (16 [77047]) User-Agent: KNode/0.4 Xref: archiver1.google.com comp.lang.ada:30267 Date: 2002-11-01T09:31:20+01:00 List-Id: Ulrich Eckhardt wrote: > Thats exact my problem. I have no idea how to do it a better way. > I use the package registry as some sort of interface, which sould > make sure that for every instance a set of functions are declared. > > But i can not or don't know how to declare an abstract type > and assign later on a real type which is derived from this type. > For example on java i can create an abstract type and also declare > a variable of an abstract type. Later on the programm i can then > instantiate a real type an assign it to this variable. Thats what i > now want to do in java. You cannot have a variable of an abstract type. Abstract types have no instances. Probably you want a variable which type is derived from some abstract type. Maybe you do not know the exact type of the variable. If so you could use class-wide objects. Make your registry object a non-limited type to have an ability to declare an abstract "constructor": package Registry is type Registry_Object is abstract tagged private; function Create (...) return Registry_Object is abstract; function Get (...) return ... is abstract; procedure Put (...) is abstract; private ... end Registry; package Registry.UNIX is type UNIX_Registry_Object (<>) is new Registry_Object with private; function Create (...) return UNIX_Registry_Object; ... UNIX_Registry_Object isn't abstract, so you have to implement all abstract primitive operations: Create, Get, Put. An instance of Registry_Object'Class can be then created as follows: My_Registry : Registry_Object'Class := Registry.UNIX.Create (...); Registry_Object is abstract. But Registry_Object'Class is not. It might look useless in this example because the specific type of My_Registry is statically known, but it will have much sense if you would later create some sort of a registry factory package: with Registry.UNIX; with Registry.POSIX; ... package Registry.Factory is type Registry_Type is (UNIX, POSIX, WINDOWS, ...); function Create (Which : Registry_Type, ...) return Registry_Object'Class; ... Then you could well hide all nasty details: with Registry; use Registry; with Registry.Factory; use Registry.Factory; ... My_Registry : Registry_Object'Class := Create (UNIX, ...); -- Regards, Dmitry Kazakov www.dmitry-kazakov.de