Hi Mark,

In the example below, I would regard this change as being an
incompatible change anyway. Code using the new API isn't compatible with
code implementing the old API because an exception can be thrown when
invoking a normal-looking method. Maybe if the new method's javadoc
explicitly states that "some implementations may not support this
operation and will throw an exception" but even then it feels wrong to
me.

There are some cases where this pattern does work, though.

Commons-digester declares Rule as an abstract class rather than an
interface. This allowed the begin/body/end methods to be enhanced with
additional parameters, with the new methods delegating back to the old
ones by default. This pattern is also described in the eclipse doc
referenced by Stephen below. There isn't any interface involved, though:
an abstract class is used *in place of* an interface.

In commons-digester 2.x (nowhere near release yet), Action is an
interface whose javadoc declares explicitly that it may change in minor
releases, and that users should subclass AbstractAction instead:
http://svn.apache.org/repos/asf/jakarta/commons/proper/digester/branches/digester2/src/java/org/apache/commons/digester2/

Regards,

Simon

-- 
A. Because it breaks the logical sequence of discussion
Q. Why is top posting bad?

On Sun, 2005-06-12 at 22:21 -0400, Mark Diggory wrote:
> 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]

Reply via email to