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: fdb77,953e1a6689d791f6 X-Google-Attributes: gidfdb77,public X-Google-Thread: fac41,953e1a6689d791f6 X-Google-Attributes: gidfac41,public X-Google-Thread: 103376,953e1a6689d791f6 X-Google-Attributes: gid103376,public X-Google-Thread: 1108a1,953e1a6689d791f6 X-Google-Attributes: gid1108a1,public X-Google-Thread: f79bb,953e1a6689d791f6 X-Google-Attributes: gidf79bb,public From: shang@corp.mot.com (David L. Shang) Subject: Re: Eiffel and Java Date: 1996/10/31 Message-ID: <1996Oct31.162218.8386@schbbs.mot.com>#1/1 X-Deja-AN: 193626967 sender: news@schbbs.mot.com (SCHBBS News Account) references: <55562c$nkd@mulga.cs.mu.OZ.AU> 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-10-31T00:00:00+00:00 List-Id: In article <55562c$nkd@mulga.cs.mu.OZ.AU> fjh@mundook.cs.mu.OZ.AU (Fergus Henderson) writes: > Suppose I have two existing library classes (perhaps supplied by different > vendors) which have some commonality, but don't inherit from a common > base class. In Sather, one can simply create a new interface and > declare these classes to be instances of this interface, without > modifying the existing code. > > (Is that possible in Java?) > No. Java supports only top-down class hierarchy construction (from superclass to subclasses), but not bottom-up: from subclasses to superclass. But Sather's superclass construction is limited to non-parametrerized classes only. Transframe provides a more powerful superclass construction that can support parameterized classes. Suppose we have two existing classes class Stack #(MemberType: type of any) { function push(MemberType); function pop:MemberType; } class Queue #(MemberType: type of any) { function push(MemberType); function pop:MemberType; } and later, we decide to have a superclass from them, we can have class StackOrQueue #(MemberType: type of any) is super Stack, Queue { function push(MemberType); function pop:MemberType; } without modifying the existing subclasses. Now, we can write polymophic code like: 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(); We can do the push without knowing whether "x" is a queue or a stack; we don't know the exact member type either, the type assurance statement will guarantee that the program free of run-time type exceptions. David Shang