Re: Separation of API and implementation



On 14.08.2007, Dmitry A. Kazakov <mailbox@xxxxxxxxxxxxxxxxx> wrote:
On Tue, 14 Aug 2007 14:32:28 -0000, hforco2@xxxxxxxxxxxxxx wrote:
But often hierarchies aren't not really parallel. Either X or Y could be
designed class-wide. Then you dispatch along the opposite axis and no
second dispatch (poorly emulated by a cast in your example) is needed.

Can you give an example of this - I don't fully understand what you
mean by 'class-wide'?

[..]
Consider X1, X2, X3 ... derived from X and Y1, Y2, ... derived from Y. foo
is defined for all possible combinations of Xi, Yj. Now there exist four
variants:

1. Full multiple dispatch is when for each combination there exists a
distinct implementation of foo. Java cannot this.
[..]

You cannot have this in Java due to numerous limitations of. So you have to
reduce it to either 2 or 3, or else emulate double dispatch in some quite
tricky way.


In Java this limitation can be partially walked round by using the
Visitor pattern for hierarchy Y while distpatching on X.
Of course all Y classes have to be under control of the writer of
the method - it won't work with 3rd party classes.

I've come across a project that claims to add multiple dispatch to Java
but I've never used it.
http://multijava.sourceforge.net/

--
Wiktor Moskwa
.



Relevant Pages

  • Re: Help! Swing & Threads
    ... The significant methods are java.awt.EventQueue isDispatchThread, invokeLater and invokeAndWait. ... It wouldn't be safe for Java to just make a new thread and call some more events... ... O'Reilly's Learning Java does this in it's example for the JFileChooser.) ... There is now Java Concurrency in Practice by Brian Goetz, Joshua Bloch, Joseph Bowbeer, Doug Lea, David Holmes and Tim Peierls, but I'm still waiting for Amazon to dispatch myu copy. ...
    (comp.lang.java.help)
  • Re: Python syntax in Lisp and Scheme
    ... In Java, methods with the same name but different ... methods at compile time can't also be used to select methods at run time. ... The claim that congruent argument lists are necessary for multi-method ... dispatch is clearly false. ...
    (comp.lang.python)
  • Re: Python syntax in Lisp and Scheme
    ... In Java, methods with the same name but different ... methods at compile time can't also be used to select methods at run time. ... The claim that congruent argument lists are necessary for multi-method ... dispatch is clearly false. ...
    (comp.lang.lisp)
  • Re: Basic oder nicht?
    ... Java macht pro am Dispatch beteiligten Objekt einen single Dispatch über ... Also schiebst Du bei einem multiplen Dispatch mit Bibliotheksobjekten noch ... Würgaround von Java gar nicht kennen. ... Das macht der JIT-Compiler von Java auch. ...
    (de.org.ccc)
  • Re: Building things out of nothing at all
    ... (define (dispatch m) ... for instance x y in the definition of cons ... car and cdr choosing a function (as it would in Java), ... closure is an object with variables x and y, and a function dispatch, ...
    (comp.lang.scheme)