comp.lang.ada
 help / color / mirror / Atom feed
From: ncohen@watson.ibm.com (Norman H. Cohen)
Subject: Re: Mut. Recurs. in Ada9X w/o Breaking Encaps.? (LONG)
Date: 30 Sep 1994 20:27:49 GMT
Date: 1994-09-30T20:27:49+00:00	[thread overview]
Message-ID: <36hsc5$g1q@watnews1.watson.ibm.com> (raw)
In-Reply-To: 1994Sep29.133526.2134@swlvx2.msd.ray.com

In article <1994Sep29.133526.2134@swlvx2.msd.ray.com>, jgv@swl.msd.ray.com
(John Volan) writes: 

|> 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.
...
|> 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.

The five lines just above seem to contradict your earlier statement that
the pointer types (the imnplementation of the binary association between
offices and employees) should be private, so I'll assume you really meant
what you said the first time and not the second time.  Pasting together
bits and pieces of solutions proposed by Mark Biggar, Magnus Kempe, and
me, isn't the following all that you're really looking for?

   package Employees_And_Offices is

      type Employee_Parent is abstract tagged private;
      type Employee_Pointer is access Employee_Parent'Class;

      type Office_Parent is abstract tagged private;
      type Office_Pointer is access Office_Parent'Class;

      -- Nondispatching  operations concerned with the relationship
      --    between offices and employees: 

      function Office_Occupied_By
         (The_Employee: Employee_Parent'Class) return Office_Pointer;

      function Employee_Occupying
         (The_Office: in Office_Parent'Class) return Employee_Pointer;

      procedure Occupy
         (The_Employee : in Employee_Pointer;
          The_Office   : in Office_Pointer);

   private

      type Employee_Parent is tagged
         record
            Its_Occupied_Office: Office_Pointer;
         end record;

      type Office_Parent is tagged
         record
            Its_Occupying_Employee: Employee_Pointer;
         end record;

   end Employees_And_Offices;


   package Employees_And_Offices.Employees is

      type Employee is new Employee_Parent with private;

      [Operations concerned with the Employee "other stuff"]

   private

      type Employee is new Employee_Parent with
         record
            [the other stuff]
         end record;

   end Employees_And_Offices.Employees;


   package Employees_And_Offices.Offices is

      type Office is new Office_Parent with private;

      [Operations concerned with the Office "other stuff"]

   private

      type Office is new Office_Parent with
         record
            [the other stuff]
         end record;

   end Employees_And_Offices.Offices;

Employee and Office can each see the other's links to itself, but each
type's "other stuff" is hidden from the other.  Outside clients can't
even see the links, just the subprograms for manipulating the links.

--
Norman H. Cohen    ncohen@watson.ibm.com



  reply	other threads:[~1994-09-30 20:27 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
1994-09-30 20:27       ` Norman H. Cohen [this message]
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