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=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: fac41,953e1a6689d791f6 X-Google-Attributes: gidfac41,public X-Google-Thread: fdb77,953e1a6689d791f6 X-Google-Attributes: gidfdb77,public X-Google-Thread: f79bb,953e1a6689d791f6 X-Google-Attributes: gidf79bb,public X-Google-Thread: 1108a1,953e1a6689d791f6 X-Google-Attributes: gid1108a1,public X-Google-Thread: 103376,953e1a6689d791f6 X-Google-Attributes: gid103376,public From: jsa@alexandria (Jon S Anthony) Subject: Re: Eiffel and Java Date: 1996/11/05 Message-ID: #1/1 X-Deja-AN: 194752198 sender: news@organon.com (news) references: <1996Nov4.142715.5411@schbbs.mot.com> organization: Organon Motives, Inc. newsgroups: comp.lang.eiffel,comp.lang.ada,comp.lang.sather,comp.lang.java.advocacy,comp.object Date: 1996-11-05T00:00:00+00:00 List-Id: In article <1996Nov4.142715.5411@schbbs.mot.com> shang@corp.mot.com (David L. Shang) writes: > In article jsa@alexandria (Jon S Anthony) writes: > > But in general it is _trivial_ to do in Ada. Note that "inheritance" > > aspects need not (and typically will not) even enter into the > > "equation" since the functionality is provided by separating the > > "module" aspect of class from the "type" aspect and allowing the > > module aspect to have separate spec. and impl. > > > > Don't you think that the Ada's code is rather complicated and > involves too many concepts to describe things clearly? The "solution" I gave is indeed just plain not the right one. As Robert Eachus pointed out, this is interface inheritance (with the ability to have multipe impls of the interface(s)) and the way this should be handled here is with generic formal packages. I suppose I should write up that solution and see how well it goes (in terms of "verbosity and complex"). > with Stack_Or_Queue; > package SQ_T1 is new Stack_Or_Queue(T1); > package ST1 renames SQ_T1.S; > package SQ_T2 is new Stack_Or_Queue(T2); > package QT2 renames SQ_T2.Q; > S : ST1; > Q : QT2; > if (some condition) then > declare > X : SQ_T1(S, null); -- X is a stack of T1s > Y : SQ_T1.Any := Get_Object; > begin > push(Y, Onto => X); > end; > else > declare > X : SQ_T2(null, Q); -- X is a queue of T2s > Y : SQ_T2.Any := Get_Object; > begin > ... > end if; > > And the above Ada's code is still not equivalent to Transframe's > code. There is no polymophism on the generic class StackOrQueue Actually, there is - but wrt to implementations. > in Ada's code: the variable "X" is not polymorphic, and is only It is on the various possible implementations of Qs & Ss, but not otherwise. > [X..] is only valid within a local scope. What happen if I want a > function to return the value of "X" for other people to use? For > example: Right. > use StackOrQueue; > function CreateStackOrQueue(some_condition: bool): StackOrQueue > { > x: StackOrQueue; > if (some_condition) x := Stack#(T1)(); else x:=Queue#(T2)(); > y: any= GetObject(); > while (y) > { > assume (y is x#.MemberType) x.push(y); > otherwise do_nothing(); > y:= GetObject(); > } > return x; > } Actually, this is not a problem in the above "solution". You can certainly return X from either scope (assuming a function context). I will see how this fits with the "correct" sort of solution using package parameters. /Jon -- Jon Anthony Organon Motives, Inc. Belmont, MA 02178 617.484.3383 jsa@organon.com