apex-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Siyuan Hua <siy...@datatorrent.com>
Subject How to make high-level API easy to extend
Date Mon, 16 May 2016 18:09:03 GMT
Hi guys
The core part of the high-level API is the Stream interface. It includes
some build-in transformations. And We want to make it easily extensible,
but java language has some limitation to prevent us from doing this.

Here is an example:


*interface Stream<T> {*

*  <O> Stream<O> map(Function<T, O> f)*
*}*



*class StreamImpl<T> implement Stream<T> {  .....}*

If you extend your own stream implementation

*class YourStreamImpl<T> extends StreamImpl {*

*  <O> YourStreamImpl<O> enrich(Function<T, O> f)*
*}*


It won't compile if you do

*new YourStreamImpl<String>().map().enrich()*
Here are some options to solve this problem with some compromise.
1. Keep this way but developer needs to do type cast

*((YourStreamImpl<String>)new YourStreamImpl<String>().map()).enrich()*
2. Change the interface to something below

*interface Stream<T> {*
*  <O, STREAM extends Stream<O>> STREAM map(Function<T, O> f)**}*
then you can do something like this *new YourStreamImpl<String>().<String, *

*YourStreamImpl<String>>map().enrich()*
3. Wipe out the type variable

*interface Stream {*
*  <STREAM extends Stream> STREAM map(Function f)**}*
then you can always do
*new YourStreamImpl().map().enrich*
The problem here is you lose the compile time type checking

4. Leave the flexibility to scala API not java. Remember you can extend the
functionality from Function/Operator interface(We will add apex module
support later).

Please let me know your preference or if you have better idea.

Thank you,
Siyuan

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message