FWIW, in another little project I used a pattern for this that avoids
implementation inheritance that I call self-delegation.
Here's an example:

/** Not put API, but it includes the impl for al getters and setters for all
types. **/
final class JsArray extends JavaScriptObject {
...
  public int getInt(int index) {
    assert indexIsInBounds(index);
    return getIntImpl(index);
  }

  public void setNumber(int index, double value) {
    assert isNumber(value);
    setNumberImpl(index, value);
  }

  private native int getIntImpl(int index) /*-{
    return this[index];
  }-*/;

  private native void setNumberImpl(int index, double value) /*-{
    this[index] = value;
  }-*/;
...
}

/** Public API */
public final class IntArray extends DataStructure {
  public static IntArray create() {
    return JavaScriptObject.createArray().cast();
  }

  protected IntArray() {
  }

  public int get(int index) {
    return this.<JsArray>cast().getInt(index);
  }

  public int getSize() {
    return this.<JsArray>cast().getSize();
  }

  public void set(int index, int value) {
    this.<JsArray>cast().setNumber(index, value);
  }
}

/kel

On Fri, Mar 27, 2009 at 1:41 PM, Bruce Johnson <[email protected]> wrote:

> Let's not add this extra type JsArrayBase into the hierarchy. Why can't we
> just push the various methods down? We can always factor upward in the
> future. If we need shared implementation, we can factor that out into a
> package-private JsArrayImpl class.
>
>
> On Fri, Mar 27, 2009 at 1:28 PM, Freeland Abbott <
> [email protected]> wrote:
>
>> Scott, we already talked about this, but here's the patch for public
>> review.
>>
>> The basic goal is to surface the native length, sort, push, and shift
>> operators for JsArrays... I know you mentioned that IE6's push may be slower
>> than indexed extension, and thus a candidate for deferred binding, but I
>> wanted to get a basic implementation in first.
>>
>> There should be only checkstyle changes from what we discussed (though
>> that obviously doesn't help the rest GWTC).  I also added some checkstyle
>> fixes to JavaScriptObject, introduced by my c5082.
>>
>> >>
>>
>


-- 
If you received this communication by mistake, you are entitled to one free
ice cream cone on me. Simply print out this email including all relevant
SMTP headers and present them at my desk to claim your creamy treat. We'll
have a laugh at my emailing incompetence, and play a game of ping pong.
(offer may not be valid in all States).

--~--~---------~--~----~------------~-------~--~----~
http://groups.google.com/group/Google-Web-Toolkit-Contributors
-~----------~----~----~----~------~----~------~--~---

Reply via email to