This is where the strategy I was referring to comes in. Lets say for instance that the following API is the case:

public interface Foo {
public Object getBar(); }

With the following "Stub" implementation.

public class FooImpl implements Foo {
   public Object getBar() {
       throw new UnsupportedOperationException();
   }
}

A third party implements this Stub like so:

public class MyFooImpl extends FooImpl {
   public Object getBar() {
       return new String("Bar");
   }
}

After which the designers of the Foo API decide its important to also provide a setter for Foo. So they add the method to both the stub and the interface like so:

public interface Foo {
   public Object getBar();
public void setBar(Object bar); }

public class FooImpl implements Foo {
   public Object getBar() {
       throw new UnsupportedOperationException();
   }
   public void setBar(Object bar) {
       throw new UnsupportedOperationException();
} }

Now, was third parties implementation broken because of this interface change? No. The Stub provides continued backward compatibility for the thirdparty implementation.

-Mark

Stephen Colebourne wrote:


Simon Kitching wrote:

So looking at possible solutions...

The current situation is:
  interface Foo
  class Impl implements Foo

Is it possible to do this?
  interface ExtendedFoo implements Foo
  class Impl implements ExtendedFoo

In this way, Foo doesn't change, but new code can pass objects around as
ExtendedFoo in order to access the new functionality.

[NB: I'm not actually suggesting a literal use of the prefix Extended. A
real, meaningful, name should be selected]

Alternatively how about this?
  interface NewStuff
  class Impl implements Foo, NewStuff


Indeed, all are possible solutions, as is
interface Foo2 extends Foo

Also, if you haven't read it, http://eclipse.org/eclipse/development/java-api-evolution.html is a *very* good read on this topic.

Stephen

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to