comp.lang.ada
 help / color / mirror / Atom feed
From: "John Duncan" <jddst19+@pitt.edu>
Subject: Re: Private Children
Date: 1999/06/23
Date: 1999-06-23T00:00:00+00:00	[thread overview]
Message-ID: <7krjrn$ddi$1@usenet01.srv.cis.pitt.edu> (raw)
In-Reply-To: 7kr4pc$bb9@dfw-ixnews15.ix.netcom.com

>This example follows the Modula-2 convention for information
>hiding using opaque types. Note that Modula-3 improves upon this
>through reference types that are followed with a reserved word,
>REVEAL,in the IMPLEMENTATION MODULE.


Just a note: M3 allows the revelation of opaque subtypes at the interface
level as well. That way you can publish a number of increasingly-challenging
interfaces to a type, some of them unsafe, provided that the base
implementation exports all of the interfaces. This way, you can have
something like

INTERFACE Thingy;
    TYPE T <: Public;
    TYPE Public = OBJECT METHODS safeMethods END;

    ...
END Thingy;

UNSAFE INTERFACE ThingyUnsafe;
    IMPORT Thingy;
    REVEAL Thingy.T <: Unsafe;
    TYPE Unsafe =
        Thingy.T
        OBJECT attributes
        METHODS
            unsafeMethods
        END;

    ...
END ThingyUnsafe;

UNSAFE MODULE Thingy EXPORTS ThingyUnsafe;
IMPORT ThingyUnsafe;
    REVEAL T =
    ThingyUnsafe.Unsafe
    OBJECT
        moreAttributes
    METHODS
        moreMethods
    OVERRIDES
        ifaceMethod := MyMethodProcedure;
    END;

    ...

END Thingy;

The little "<:" operator tells the compiler about the subtyping relation.
Each of the times T is declared as a subtype, it becomes more concrete, but
not concrete enough to compile. When it comes down to the module level,
someone has to define the type concretely. In order to do this, the methods
are usually null until someone comes along and overrides the previous
methods. It all works out very, very nicely.

A lot of people on the m3 ng wonder whether the Ada committee reviewed
opaque subtypes at all. It is a very neat feature for deep-down systems
programming. There is no particular reason why unsafe things have to be
published outside a library, but they are usually very useful within the
library. That's where the opaque subtyping and partial revelations come in.

(for more info on modula-3, go to http://www.m3.org/ )

-John






  parent reply	other threads:[~1999-06-23  0:00 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1999-06-20  0:00 Private Children Matthew Heaney
1999-06-21  0:00 ` Dale Stanbrough
1999-06-21  0:00 ` Ted Dennison
1999-06-21  0:00   ` Tucker Taft
1999-06-21  0:00     ` Matthew Heaney
1999-06-21  0:00       ` Tucker Taft
1999-06-22  0:00         ` Richard D Riehle
1999-06-22  0:00           ` Dale Stanbrough
1999-06-22  0:00             ` Richard D Riehle
1999-06-22  0:00             ` Matthew Heaney
1999-06-23  0:00               ` Dale Stanbrough
1999-06-23  0:00                 ` Matthew Heaney
1999-06-23  0:00                   ` Dale Stanbrough
1999-06-23  0:00                     ` Richard D Riehle
1999-06-23  0:00                       ` Vladimir Olensky
1999-06-23  0:00                         ` Richard D Riehle
1999-06-24  0:00                           ` Hyman Rosen
1999-06-24  0:00                             ` Richard D Riehle
1999-06-23  0:00                       ` John Duncan [this message]
1999-06-24  0:00                       ` Dale Stanbrough
1999-06-21  0:00     ` Matthew Heaney
1999-06-25  0:00   ` Robert Dewar
replies disabled

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