Re: Separation of API and implementation
- From: Wiktor Moskwa <wiktorDOTmoskwa@xxxxxxxxx>
- Date: Tue, 14 Aug 2007 20:03:12 +0000 (UTC)
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
.
- References:
- Separation of API and implementation
- From: hforco2
- Re: Separation of API and implementation
- From: Dmitry A. Kazakov
- Re: Separation of API and implementation
- From: hforco2
- Re: Separation of API and implementation
- From: Dmitry A. Kazakov
- Separation of API and implementation
- Prev by Date: Re: Separation of API and implementation
- Next by Date: Re: Pattern/s sought
- Previous by thread: Re: Separation of API and implementation
- Next by thread: Re: Separation of API and implementation
- Index(es):
Relevant Pages
|