2

I've got some 3rd party beans that have method signatures that fit quite well onto an existing interface but it does not implement the interface.

Now I would like to do something like this, which doesn't work. Is there some workaround?

 someBean.setSomeInterface(
         new Interface() extends SomeBeanThatMatchesAlotOfMethodsOfTheInterface {
     });
Franz Kafka
  • 10,623
  • 20
  • 93
  • 149

2 Answers2

2

I think about all you could do is extend their class (like you did above) and then say implements.

Eg.

public class MyImplementingClass extends SomeBeanThatMatchesAlotOfMethodsOfTheInterface implements MyInterface {

....
}

Of course by basing their code on your interface it is possible that it could break in the future. Just be aware of that.

Chris Aldrich
  • 1,904
  • 1
  • 22
  • 37
2

You can use a decorator pattern for this

Define a class that implements your interface and in all the method calls delegate to the someBean implementation.

Cratylus
  • 52,998
  • 69
  • 209
  • 339