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.2 required=5.0 tests=BAYES_00,INVALID_MSGID, REPLYTO_WITHOUT_TO_CC 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: 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 X-Google-Thread: fdb77,953e1a6689d791f6 X-Google-Attributes: gidfdb77,public From: shang@corp.mot.com (David L. Shang) Subject: Re: Eiffel and Java Date: 1996/11/04 Message-ID: <1996Nov4.142715.5411@schbbs.mot.com>#1/1 X-Deja-AN: 194502554 sender: news@schbbs.mot.com (SCHBBS News Account) references: organization: MOTOROLA reply-to: shang@corp.mot.com newsgroups: comp.lang.eiffel,comp.lang.ada,comp.lang.sather,comp.lang.java.advocacy,comp.object Date: 1996-11-04T00:00:00+00:00 List-Id: In article jsa@alexandria (Jon S Anthony) writes: > In article <1996Oct31.162218.8386@schbbs.mot.com> shang@corp.mot.com (David L. Shang) writes: > > > No. Java supports only top-down class hierarchy construction > > (from superclass to subclasses), but not bottom-up: from > > subclasses to superclass. > > 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? Transframe's version: use Stack, Queue; class StackOrQueue #(MemberType: type of any) is super Stack, Queue { function push(MemberType); function pop:MemberType; } use StackOrQueue; function MyTestCode() { x: StackOrQueue; if (some_condition) x = Stack#(T1)(); else x:=Queue#(T2)(); y: any = GetObject(); assume (y is x#.MemberType) x.push(y); otherwise do_nothing(); .... } Your Ada's Version: with Stacks; -- Generic with Queues; -- Generic generic type Any_Obj is tagged private; package Stack_Or_Queue package S is new Stacks(Any_Obj); package Q is new Queues(Any_Obj); type Any is access all Any_Obj'Class; type Stack_Queue ( S : access S.Stack; Q : access Q.Queue ) is private; procedure Push (Element : Any; Onto : Stack_Queue); function Pop (SQ : Stack_Queue) return Any; private type Stack_Queue ... end Stack_Or_Queue; 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 in Ada's code: the variable "X" is not polymorphic, and 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: 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; } David Shang