comp.lang.ada
 help / color / mirror / Atom feed
From: jgv@swl.msd.ray.com (John Volan)
Subject: Re: Mut. Recurs. in Ada9X w/o Breaking Encaps.? (LONG)
Date: Thu, 29 Sep 1994 13:35:26 GMT
Date: 1994-09-29T13:35:26+00:00	[thread overview]
Message-ID: <1994Sep29.133526.2134@swlvx2.msd.ray.com> (raw)
In-Reply-To: 1994Sep29.103358@di.epfl.ch

MK = Magnus.Kempe@di.epfl.ch (Magnus Kempe) writes:

MK>Norm's solution could be further improved as follows:
MK>
MK>: One variation on this is to declare recursive types meant to serve as the
MK>: parents of types Employee and Office, but to provide no operations for
MK>: these recursive types.  Then, in child packages, declare Employee and
MK>: Office themselves as derived types and declare primitive operations in
MK>: those child packages: 
MK>
MK>Since this couple of recursive types is strictly internal to the
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
MK>abstraction "employee and his office", I recommend that they be
   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Not true.  The premise of my original question was that the binary association
between Employee and Office is a public feature fully visible to their
clients -- and they could even include each other as clients!  Maybe the
*implementation* of this binary association is strictly internal to the
abstraction (I agree that it should be), but the *existence* of this binary
association should be a visible part of this abstraction.  In other words,
the interface to the Employee class should include some subprogram(s) that
allow(s) a client to fetch the identity of (a pointer to) the associated Office.
Likewise the interface to the Office class should include some subprogram(s)
that allow(s) a client to fetch the identity of (a pointer to) the associated
Employee.  And the interface to both classes should include some subprogram(s)
that allow a client to establish an association between a given Office and a
given Employee, in such a way as to always guarantee the following invariant
assertion:

	For any given Employee "E" and Office "O",
	E occupies O if and only if O is occupied by E.


MK>declared as abstract and hidden in the private part of the parent
MK>package (Yes, this compiles with GNAT):
MK>
MK>    package Company is
MK>    private
MK>      type Employee_Parent;
MK>      type Employee_Pointer is access all Employee_Parent'Class;
MK>
MK>      type Office_Parent;
MK>      type Office_Pointer is access all Office_Parent'Class;
MK>
MK>      type Employee_Parent is abstract tagged
MK>        record
MK>          Its_Occupied_Office : Office_Pointer;
MK>        end record;
MK>
MK>      type Office_Parent is abstract tagged
MK>        record
MK>          Its_Occupying_Employee : Employee_Pointer;
MK>        end record;
MK>    end Company;
MK>
MK>The rest of Norm's solution doesn't change; the couple of abstractions
MK>Employee and Office is declared in two child units of Company.  To the
MK>client programmer, the encapsulation is strong but the relationship
MK>between the two abstractions is quite apparent because they are exported
MK>by the Company.* subsystem (a hierarchy of packages).


Unfortunately, hiding the pointer types within the private part of the parent
prevents them from being visible to clients, even via child packages.  This 
defeats the whole purpose of having a mutually recursive *abstraction* --
that is, something that provides an *interface* to some useful services while 
encapsulating the *implementation* of those services.


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


-- John Volan

--------------------------------------------------------------------------------
--  Me : Person := (Name                => "John Volan",
--                  Company             => "Raytheon Missile Systems Division",
--                  E_Mail_Address      => "jgv@swl.msd.ray.com",
--                  Affiliation         => "Enthusiastic member of Team Ada!",
--                  Humorous_Disclaimer => "These opinions are undefined " &
--                                         "by my employer and therefore " &
--                                         "any use of them would be "     &
--                                         "totally erroneous.");
--------------------------------------------------------------------------------



  parent reply	other threads:[~1994-09-29 13:35 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
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 [this message]
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