From: Dmitry A.Kazakov <mailbox@dmitry-kazakov.de>
Subject: Re: problem with abstract types
Date: Fri, 1 Nov 2002 09:31:20 +0100
Date: 2002-11-01T09:31:20+01:00 [thread overview]
Message-ID: <aprvui$4ftli$1@ID-77047.news.dfncis.de> (raw)
In-Reply-To: r3frpa-ja1.ln@uli.uli-eckhardt.de
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
next prev parent reply other threads:[~2002-11-01 8:31 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-10-31 12:06 problem with abstract types Ulrich Eckhardt
2002-10-31 13:15 ` John English
2002-10-31 14:43 ` Ulrich Eckhardt
2002-10-31 17:18 ` Robert I. Eachus
2002-10-31 18:20 ` Jeffrey Carter
2002-10-31 20:58 ` Robert I. Eachus
2002-11-01 10:57 ` Ulrich Eckhardt
2002-11-01 12:05 ` Simon Wright
2002-11-01 17:03 ` Robert A Duff
2002-11-04 15:18 ` Robert I. Eachus
2002-11-04 16:14 ` Robert A Duff
2002-10-31 13:32 ` David C. Hoos
2002-10-31 13:47 ` problem with posters Peter Hermann
2002-10-31 14:15 ` Preben Randhol
2002-10-31 14:35 ` problem with abstract types Ulrich Eckhardt
2002-11-01 8:31 ` Dmitry A.Kazakov [this message]
2002-11-01 11:32 ` Ulrich Eckhardt
2002-10-31 15:31 ` Simon Wright
2002-10-31 17:22 ` Stephen Leake
2002-11-01 10:25 ` Ulrich Eckhardt
2002-11-04 14:30 ` Ted Dennison
2002-11-04 15:08 ` Ulrich Eckhardt
2002-11-04 15:32 ` Stephen Leake
2002-11-04 17:12 ` Ulrich Eckhardt
2002-11-04 17:43 ` David C. Hoos
2002-11-04 19:34 ` Ulrich Eckhardt
2002-11-04 19:54 ` Stephen Leake
2002-11-04 20:08 ` Robert A Duff
2002-11-01 11:15 ` Preben Randhol
2002-11-01 17:21 ` Stephen Leake
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox