comp.lang.ada
 help / color / mirror / Atom feed
From: Ivan Levashew <octagram@bluebottle.com>
Subject: Re: Interfaces and abstract tagged types
Date: Wed, 22 Oct 2008 23:39:10 -0700 (PDT)
Date: 2008-10-22T23:39:10-07:00	[thread overview]
Message-ID: <4ba8b27d-6228-4451-bfc6-ef19dd4b96cb@k13g2000hse.googlegroups.com> (raw)
In-Reply-To: 48f716fc$0$28911$9b4e6d93@newsspool1.arcor-online.net

> For the JNI and similar?

Unlikely. CORBA mapping works fine without interfaces.

Some notes on the subject itself:

Usually, interfaces should be preferred. But sometimes there are cases
where different objects must closely interact, and they explicitly
must have a common internal represenation.

Consider 2 examples:

1. You have a set of objects. This set is internally sorted somehow.
You'd like to have a "&"(Left, Right : Set_Type) operation. Although
it's pretty possible to compose an universal merge implementation
being able to inefficiently merge vendor A's set and vendor B's set,
one would like to use efficient merges. In this case, Left and Right
must have something in common, that is, be an descendants of abstract
tagged type instead of interface.

2. Another case is sockets. There is a "select()" procedure in Sockets
API. Let's assume that there are several finite state machines
operating on sockets streams. Vendor A's FSM and vector B's FSM must
have a common internals in order to be able to be used in a "select()"
call. Once again, abstract tagged type is preferred over interface
here.

There's a bad option to define "anti-interface" exposing desired
internals, e. g. socket handle. Don't do like this.

---------------------

> The perversion is that inheritance as form of polymorphism is
> technically
> replaced by another form of (parametric polymorphism). What are
> interfaces for, if generics must be used instead?

Interfaces are for run-time polymorphism, the final goal.
Generics is just an aid to do it in a handy way.

> In order to handle this exponentially exploding code,
> generics are
> introduced down the tree. I.e. Bi becomes a generic and
> interfaces are
> passed as formal parameters of. Then the generic instances
> are passed down
> the tree to lower generics.

Right, it is supposed to be used this way. Maybe your complaints are
due to lack of good UML tools for Ada 2005?

> The interface
> cannot be inherited from a concrete type

I think this is obvious that Ada designer can't let you do this
trick. A concrete type might have more primitive operation than
interface you're want to declare. List and Vector have extra
operations that can be done efficiently. How can Ada compiler be sure
whether you'd like to treat Vector implementation as an implementation
of hypothethic Vector_Interface or whether Vector is just an
enumerable container. If it's really the case that every primitive
operation must be copied to the interface, this fact must be stated
explicitly.



  parent reply	other threads:[~2008-10-23  6:39 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-10-05  7:01 Interfaces and abstract tagged types Dale Stanbrough
2008-10-05  7:43 ` Dmitry A. Kazakov
2008-10-05 20:29   ` Robert A Duff
2008-10-06  8:25     ` Dmitry A. Kazakov
2008-10-16  7:51       ` Ivan Levashew
2008-10-16  8:29         ` Dmitry A. Kazakov
2008-10-16  9:23           ` Ivan Levashew
2008-10-16 10:05             ` Dmitry A. Kazakov
2008-10-16 10:27               ` Georg Bauhaus
2008-10-16 12:21                 ` Dmitry A. Kazakov
2008-10-16 13:35                   ` Georg Bauhaus
2008-10-16 14:30                     ` Dmitry A. Kazakov
2008-10-23  6:39                 ` Ivan Levashew [this message]
2008-10-25  8:57                   ` Dmitry A. Kazakov
replies disabled

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