comp.lang.ada
 help / color / mirror / Atom feed
From: "Randy Brukardt" <randy@rrsoftware.com>
Subject: Re: using interface types: guru assistance begged
Date: Thu, 6 Jul 2006 17:50:14 -0500
Date: 2006-07-06T17:50:14-05:00	[thread overview]
Message-ID: <lqqdnR6QtY_nDjDZnZ2dnUVZ_oadnZ2d@megapath.net> (raw)
In-Reply-To: C0D2E8C5.586FF%yaldnif.w@blueyonder.co.uk

"(see below)" <yaldnif.w@blueyonder.co.uk> wrote in message
news:C0D2E8C5.586FF%yaldnif.w@blueyonder.co.uk...
> I am trying to learn how to use Ada 2005's interface types,
> using GNAT GPL 2006 on MacOS X,
> with an example along the following lines (much trimmed):
...
> As written this compiles and runs correctly.

If it does, I'd be amazed. You define something called "a_set", and then a
bit later do various operations on "a_word_set" which is never defined
anywhere. My original guess was that you forgot to change some names. But
then, you define an operation returning "a_word_set":
function bit (candidate : a_member_type) return a_word_set;
which is not abstract. So if "a_word_set" was changed to "a_set", this would
be illegal. At this point, I gave up; that's only the first package and a
quick glance at the others doesn't make it any clearer. Please repost your
code that really does compile...

Even so, I can give you a very quick answer:

> However, I would prefer the derivation of a_word_set to be private, thus:
...
> And so on, for all of the subprograms declared in generic_word_masks.
> Can anyone tell me what I am doing wrong here, and whether there is
> any way to achieve the desired information hiding?

I didn't look at the error messages; probably you need to make sure that you
are declaring an abstract type in the instance.

But in any case, the quick answer is no. Ada 2005 requires that interfaces
are never hidden. The way interfaces work is that they are a property of a
type: either it has that interface property or it does not. In particular,
it is not possible for a type to have the same interface twice.

But, if you could hide interfaces, you'd have to break privacy by looking
into the private part in order to determine whether it was OK to add an
interface to the type. (If you didn't do that, you could add the same
interface twice, with different operations defined each time. Then, if
dispatched on Interface'Class(), which operation would be called? It would
be very hard to tell.)

So Ada 2005 does not allow hiding of interfaces; all of the interfaces used
in the full view also have to be used on the private view. (They don't
necessarily have to have the same names, just the same set of interfaces.)

Rules of thumb:
   * If you need hiding, use abstract tagged types;
   * If you need concrete operations or components in the root type, use
abstract tagged types;
   * If you need multiple inheritance (more than one parent), use
interfaces;
   * If you need to complete the type with tasks or protected types, use
interfaces;
   * If you need to do a combination of the above, you're s**t out of luck.
;-)

                         Randy.





  reply	other threads:[~2006-07-06 22:50 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-07-06 15:20 using interface types: guru assistance begged (see below)
2006-07-06 22:50 ` Randy Brukardt [this message]
  -- strict thread matches above, loose matches on Subject: below --
2006-07-07 17:54 (see below)
replies disabled

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