comp.lang.ada
 help / color / mirror / Atom feed
From: Magnus.Kempe@di.epfl.ch (Magnus Kempe)
Subject: Re: Mut. Recurs. in Ada9X w/o Breaking Encaps.? (LONG)
Date: 1 Oct 1994 12:01:30 GMT
Date: 1994-10-01T12:01:30+00:00	[thread overview]
Message-ID: <1994Oct1.123822@di.epfl.ch> (raw)
In-Reply-To: Cwyzx4.H3K@irvine.com

adam@irvine.com (Adam Beneschan) writes:
: ...  the package Company is there "just to get the Ada language to do
: what you want", not to represent any concept or abstraction that has
: anything to do with the application.

This is incorrect.  The requirement is for two ADTs which are mutually
dependent.  Ada 9X offers a hierarchical namespace which allows us to
capture the fact that Employee and Office belong together (you're not
going to use one without the other), and the root package Company _holds_
that mutual dependency.

: As I understand it, inheritance's primary purpose is to model "IS-A"
: or "IS-A-KIND-OF" relationships between object types (I believe it's
: sometimes used purely for code reuse, although that seems like a
: misuse of the concept to me).  Here, inheritance doesn't really model
: anything--it's just something that got set up in order to get things
: to work.

You are right that code usually doesn't "model" anything.  It's just
there to _implement_ a model.  You seem to hold that inheritance is
good only when it corresponds exactly to an "is-a" relationship of
your model.

But there are two kinds of inheritance: interface and implementation (or
code sharing).  The first corresponds to is-A relationships; the second
is a means for code sharing.  In the particular example you cite, the
derivation was not done in the interface but in the private part, so as
to _hide_ the inheritance.


Compare undue interface inheritance (the client sees the ADT and
implementation details, as well as some List stuff which has nothing
to do with a Stack ADT)

with Lists;
package Stacks is
  type Stack_Type is
    new Lists.List_Type -- !!! Stack is-a List
    with private;
  ... -- Push, Pop, Size
  
  ... -- somehow try to hide the operations of List_Type which
      -- violate the Stack abstraction
private
  type Stack_Type is
    new List_Type
    with null record;
end Stacks;


vs. implementation inheritance (the client does not see anything
except the proper ADT)

with Lists;
package Stacks is
  type Stack_Type is
    private;
  ... -- Push, Pop, Size
private
  type Stack_Type is
    new Lists.List_Type -- !!! Stack is-implemented-by-a List
    with null record;
end Stacks;


There is nothing revolutionary here, and nothing peculiar to Ada.  The
distinction between interface and implementation inheritance is quite
common and useful.  One may have a dislike for implementation inheritance,
but that's no sufficient reason to forbid its use to those who do find
it advantageous.  Is it an ugly "workaround"?  Maybe, to the extent that
someone somewhere will castigate any high-level language mechanism for
being a workaround of their favorite assembly language feature.

-- 
Magnus Kempe		"I know not what course others may take, but as for me,
Magnus.Kempe@di.epfl.ch  Give me Liberty... or give me Death!" -- Patrick Henry



  reply	other threads:[~1994-10-01 12:01 UTC|newest]

Thread overview: 43+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1994-09-27 16:52 Mut. Recurs. in Ada9X w/o Breaking Encaps.? (LONG) John Volan
1994-09-27 18:48 ` Mark A Biggar
1994-09-29  1:46   ` John Volan
1994-09-29 13:57     ` Tucker Taft
1994-09-29 17:20       ` Bjarne Stroustrup <9758-26353> 0112760
1994-09-30  1:38         ` Tucker Taft
1994-09-30 12:33           ` Bjarne Stroustrup <9758-26353> 0112760
1994-09-29 18:37       ` John Volan
1994-09-29 19:34         ` David Weller
1994-09-30 22:13           ` John Volan
1994-10-02  3:31             ` Andrew Lees
1994-09-30  1:47         ` Tucker Taft
1994-09-30 13:30           ` John Volan
1994-09-29 18:10     ` R. William Beckwith
1994-10-03  0:33     ` Cyrille Comar
1994-09-28 14:01 ` Norman H. Cohen
1994-09-29  2:12   ` John Volan
1994-09-29 14:01     ` Tucker Taft
1994-09-29 18:37     ` Norman H. Cohen
1994-09-29  9:48   ` Magnus Kempe
1994-09-29 13:10     ` Magnus Kempe
1994-09-29 18:05       ` Tucker Taft
1994-09-30 10:20         ` Mut. Recurs. in Ada9X w/o Breaking Encaps.? Magnus Kempe
1994-09-30 13:22           ` Tucker Taft
1994-10-01  1:24       ` Mut. Recurs. in Ada9X w/o Breaking Encaps.? (LONG) Adam Beneschan
1994-10-01 12:01         ` Magnus Kempe [this message]
1994-10-01 18:43         ` Mark A Biggar
1994-10-02 16:41         ` John Volan
1994-10-02 23:33           ` Matt Kennel
1994-10-03  8:07           ` Mut. Recurs. in Ada9X w/o Breaking Encaps.? Magnus Kempe
1994-10-03 12:14           ` Mut. Recurs. in Ada9X w/o Breaking Encaps.? (LONG) Robert I. Eachus
1994-10-04  2:12             ` R. William Beckwith
1994-10-04 16:00             ` John Volan
1994-10-05 11:42               ` Robert I. Eachus
1994-10-05 21:09               ` Matt Kennel
1994-10-03 20:29           ` Harry Koehnemann
1994-09-29 13:35     ` John Volan
1994-09-30 20:27       ` Norman H. Cohen
1994-10-01  1:47         ` John Volan
1994-10-01 20:44           ` Tucker Taft
1994-10-03 11:29           ` Robert I. Eachus
1994-09-30 22:46       ` Matt Kennel
1994-10-01  2:11         ` John Volan
replies disabled

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