Article View: comp.sw.components
Article #33Re: Inheritance vs. component efficiency
From: Robert Eachus
Date: Mon, 19 Jun 1989 17:30
Date: Mon, 19 Jun 1989 17:30
64 lines
2575 bytes
2575 bytes
In article <5021@wiley.UUCP> simpson@poseidon.UUCP (Scott Simpson) writes:
->package Demo is
-> type A is limited private;
-> type B is limited private;
-> procedure X(P1 : A; P2 : B);
->end Demo;
->with Demo; use Demo;
->procedure Illustrate is
-> type S is new A; -- You get "procedure X(P1 : S; P2 : B)".
-> type T is new B; -- You get "procedure X(P1 : A; P2 : T)".
->end Illustrate;
->How do you get "procedure X(P1 : S; P2 : T)"? You can't.
You can! The easiest way is:
with Demo;
procedure Illustrate is
type S is new A; -- You get "procedure X(P1 : S; P2 : B)".
type T is new B; -- You get "procedure X(P1 : A; P2 : T)".
procedure X(P1: S; P2: T) is
begin
X(P1, B(P2));
end X;
begin ...
end Illustrate;
Of course the natural Ada approach to this (assuming that the X's with
mixed parameters are unwanted is to write:
generic
type A is limited private;
type B is limited private;
with function... -- needed operations for A and B, usually with
-- defaults.
package Demo is
procedure X(P1 : A; P2 : B);
end Demo;
with Demo;
procedure Illustrate is
type S is ...
type T is ...
package Demo is new Standard.Demo(S,T);
begin ...
end Illustrate;
This inversion of defining library packages in terms of truly
abstract types and allowing the user to define the instance types, is
common in Ada. The easiest way to think of it is that the Ada classes
are built "bottom up" instead of top down. An Ada class could be
defined to be the set of types for which a particular generic can be
sensibly instantiated. (The sensibly is because certain instantiations
are permitted at compile time, but must raise an exception during
elaboration.)
Robert I. Eachus
with STANDARD_DISCLAIMER;
use STANDARD_DISCLAIMER;
function MESSAGE (TEXT: in CLEVER_IDEAS) return BETTER_IDEAS is...
Technical Details
Message-ID:
<57062@linus.UUCP>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!apple!vsi1!wyse!mips!prls!philabs!linus!mbunix!eachusReferences:
<5186@pt.cs.cmu.edu> <5740@hubcap.clemson.edu> <5021@wiley.UUCP>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!apple!vsi1!wyse!mips!prls!philabs!linus!mbunix!eachus From: eachus@mbunix.mitre.org (Robert Eachus) Newsgroups: comp.sw.components Subject: Re: Inheritance vs. component efficiency Summary: How to example Message-ID: <57062@linus.UUCP> Date: 19 Jun 89 17:30:32 GMT References: <5186@pt.cs.cmu.edu> <5740@hubcap.clemson.edu> <5021@wiley.UUCP> Sender: news@linus.UUCP Reply-To: eachus@mbunix.mitre.org (Robert I. Eachus) Organization: The MITRE Corporation, Bedford, Mass. Lines: 64