From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=BAYES_00,INVALID_DATE autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 109fba,66253344eaef63db X-Google-Attributes: gid109fba,public X-Google-Thread: 1108a1,66253344eaef63db X-Google-Attributes: gid1108a1,public X-Google-Thread: 103376,66253344eaef63db X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 1994-09-30 23:05:46 PST Newsgroups: comp.lang.ada,comp.object,comp.lang.c++ Path: bga.com!news.sprintlink.net!redstone.interpath.net!ddsw1!news.kei.com!MathWorks.Com!news2.near.net!noc.near.net!ray.com!news.ray.com!news.ed.ray.com!swlvx2!jgv From: jgv@swl.msd.ray.com (John Volan) Subject: Re: Mut. Recurs. in Ada9X w/o Breaking Encaps.? (LONG) Date: Sat, 1 Oct 1994 02:11:00 GMT Message-ID: <1994Oct1.021100.11030@swlvx2.msd.ray.com> References: <1994Sep29.133526.2134@swlvx2.msd.ray.com> <36i4fb$hsn@network.ucsd.edu> Sender: news@swlvx2.msd.ray.com (NEWS USER) Organization: Raytheon Company, Tewksbury, MA Xref: bga.com comp.lang.ada:6355 comp.object:6950 comp.lang.c++:31199 Date: 1994-10-01T02:11:00+00:00 List-Id: mbk@inls1.ucsd.edu (Matt Kennel) writes: >How about this kind solution? I'm going to have to write in ersatz >Eiffel/Sather: Ah, you beat me to it, Matt! Or did my post get out first? Anyway... >class TWO_WAY_RELATION{T1,T2} is > private map_1_to_2:MAP{T1,T2}; -- MAP{T1,T2} is a hash table > -- data structure that finds T2's given > -- T1's as keys. > private map_2_to_1:MAP{T2,T1}; > > create is > map_1_to_2 := #MAP{T1,T2}; > map_2_to_1 := #MAP{T1,T2}; end; > > add_pair(x:T1,y:T2) is > map_1_to_2.insert(x,y); > map_2_to_1.insert(y,x); > end; > > find_one_given_two(y:T2):T1 is > return map_2_to_1.find(y); end; > > find_one_given_two(x:T1):T2 is > return map_1_to_2.find(x); end; > >end; -- class TWO_WAY_RELATION Absolutely right. Ada can certainly do that too, with generic packages. >class EMPLOYEE is > private shared mapper:TWO_WAY_RELATION{EMPLOYEE,OFFICE}; > -- shared so all instances access the same object > > find_my_office : OFFICE is ^^^^^^ Ah, but you see, this is precisely my point. You are in the midst of writing the interface (and implementation -- Eiffel does it all at once) of class EMPLOYEE. Class OFFICE has not yet been written! I'll assume that this truly works in Eiffel and that these three classes are three separate compilation units, not just one file. If so, then Eiffel is able to manage the Identity/Interface/Implementation Trichotomy I talked about a couple posts ago. > mapper.find_two_given_one(self); end; > > set_my_office(o:OFFICE) is > mapper.add_pair(self,o); end; > >end; -- EMPLOYEE > >class OFFICE is > private shared mapper:TWO_WAY_RELATION{EMPLOYEE,OFFICE} > -- shared so all instances access the same object > > find_my_employee : OFFICE is > mapper.find_one_given_two(self); end; > > set_my_employee(e:EMPLOYEE) is > mapper.add_pair(e,self); end; >end; -- OFFICE > >--- > >Now, both Office and Employee present interfaces that can find >and set each one's counterpart. Neither knows how to do this >except through the 'mapper' object, which presents a clean interface >for managing pairs. > >Comments? If this works, it's not because the mapper object did it for them. It's because Eiffel can deal with two classes that are mutually dependent even in their interfaces! (Matt, can you or some other Eiffel person confirm this?) Well, Ada folks, if this works ... need I say more? >-- >-Matt Kennel mbk@inls1.ucsd.edu >-Institute for Nonlinear Science, University of California, San Diego >-*** AD: Archive for nonlinear dynamics papers & programs: FTP to >-*** lyapunov.ucsd.edu, username "anonymous". --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."); --------------------------------------------------------------------------------