comp.lang.ada
 help / color / mirror / Atom feed
* Abstract type derivation?
@ 1996-04-08  0:00 David Weller
  1996-04-10  0:00 ` Robert A Duff
  1996-04-12  0:00 ` Geert Bosch
  0 siblings, 2 replies; 3+ messages in thread
From: David Weller @ 1996-04-08  0:00 UTC (permalink / raw)


I want to create an abstract type that is derived from Controlled
(which is itself abstract).  Either the syntax isn't clear or it can't
be done :-)  

	type Queue is new Controlled with private;
	-- allows users to declare a type Queue

	type Queue is abstract tagged private;
	-- what I want, but now I don't have "Adjust" available, major
	bummer.

Am I missing something obvious?





^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Abstract type derivation?
  1996-04-08  0:00 Abstract type derivation? David Weller
@ 1996-04-10  0:00 ` Robert A Duff
  1996-04-12  0:00 ` Geert Bosch
  1 sibling, 0 replies; 3+ messages in thread
From: Robert A Duff @ 1996-04-10  0:00 UTC (permalink / raw)


In article <4kb0hb$k87@dfw.dfw.net>, David Weller <dweller@dfw.net> wrote:
>I want to create an abstract type that is derived from Controlled
>(which is itself abstract).

    type Queue is abstract new Controlled with private;
                  ^^^^^^^^

Also, to prevent objects from being created, consider using unknown
discriminants.

- Bob




^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Abstract type derivation?
  1996-04-08  0:00 Abstract type derivation? David Weller
  1996-04-10  0:00 ` Robert A Duff
@ 1996-04-12  0:00 ` Geert Bosch
  1 sibling, 0 replies; 3+ messages in thread
From: Geert Bosch @ 1996-04-12  0:00 UTC (permalink / raw)


David wrote:
`` I want to create an abstract type that is derived from Controlled
   (which is itself abstract).  Either the syntax isn't clear or it can't
   be done :-)  ''

Hmm... I've made an abstract storage pool class (for my GNAT 
garbage collector) and it compiled just fine. Right now, the class
isn't abstract anymore, but I'm rather sure it did compile properly. I
also can't think of a reason to prohibit abstract derivations of
non-abstract types, since it's a very useful thing to have for good SE
practice.

   	type Queue is new Controlled with private;
   	-- allows users to declare a type Queue

I don't understand this comment. *You* did declare a type Queue,
so what does that have to do with users declaring a type
Queue. Do you mean a type derived from Queue, or an object
of type Queue.

   	type Queue is abstract tagged private;
   	-- what I want, but now I don't have "Adjust" available, major
   	bummer.

You give very, very little context so it's hard to guess what
you're trying to do. If you want the users of your Queue to
be able to take advantage of the fact that Queue is a controlled
type by letting them inherit Queue and override Adjust etc., then
you use your first declaration. 

When you want to completely hide the implementation of Queue
(so nobody will be able to provide a new implementation of adjust),
then your second approach is the right one. Of course the complete
declaration of Queue in the private part of the package should be 
the same as in the first case.

Below I'll give you a sample to illustrate my points and make
things more concrete.

   Am I missing something obvious?

Either you are, or I am! ;-)

Regards,
   Geert

Example code for abstract controlled types:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

with Ada.Finalization;
use Ada.Finalization;

package Queues is

   -- Queue_A implements a type that is completely abstract to the
   -- user of the package. The user can see nothing but the operations
   -- exported here.
   
   type Queue_A is abstract tagged private;
   procedure My_Operation(Q: in out Queue_A) is abstract;
   
   -- Queue_B implements a type that shows it's inheritance
   -- from Controlled, but nothing else. The user may override
   -- the Initialize, Adjust and Finalize operations.

   type Queue_B is abstract new Controlled with private;
   procedure My_Operation(Q: in out Queue_B) is abstract;
   
private

   -- In both cases the complete declaration in the private part
   -- is the same.
   type Queue_A is abstract new Controlled with null record;
   type Queue_B is abstract new Controlled with null record;
   
end Queues;

-- 
E-Mail: geert@sun3.iaf.nl     *** As far as we know, there have not been ***
 Phone: +31-53-4303054        ** any undetected failures in our software. **




^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~1996-04-12  0:00 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1996-04-08  0:00 Abstract type derivation? David Weller
1996-04-10  0:00 ` Robert A Duff
1996-04-12  0:00 ` Geert Bosch

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox