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: 103376,953e1a6689d791f6 X-Google-Attributes: gid103376,public X-Google-Thread: 1108a1,953e1a6689d791f6 X-Google-Attributes: gid1108a1,public From: fjh@murlibobo.cs.mu.OZ.AU (Fergus Henderson) Subject: Re: Eiffel and Java Date: 1996/11/02 Message-ID: <55fduh$6nc@mulga.cs.mu.OZ.AU>#1/1 X-Deja-AN: 193940257 references: <55562c$nkd@mulga.cs.mu.OZ.AU> <1996Oct31.162218.8386@schbbs.mot.com> organization: Comp Sci, University of Melbourne newsgroups: comp.lang.eiffel,comp.lang.ada,comp.lang.sather,comp.lang.java.advocacy,comp.object Date: 1996-11-02T00:00:00+00:00 List-Id: jsa@alexandria (Jon S Anthony) writes: ]shang@corp.mot.com (David L. Shang) writes: ] ]> 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. Why not? I would have thought that since Java has separate interface inheritence already, it would not be difficult to provide this feature. ]But in general it is _trivial_ to do in Ada. I'm skeptical. ]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; Can I use this stack_or_queue interface to access different implementations of the stack type (e.g. using arrays or using linked lists?) How about priority_queues? With the Sather version, anything that implements push and pop can be declared to implement the stack_or_queue interface. It looks like your stack_or_queue interface has exactly two implementations and can't be extended. (And that's despite being much more verbose and complicated than the Sather version.) -- Fergus Henderson | "I have always known that the pursuit WWW: | of excellence is a lethal habit" PGP: finger fjh@128.250.37.3 | -- the last words of T. S. Garp.