[hibernate-dev] Evolvement of SPIs
Emmanuel Bernard
emmanuel at hibernate.org
Mon Apr 2 05:16:09 EDT 2012
What's your definition of an SPI, in the team we have slightly different ones.
In Hibernate search an SPI is targeted at frameworks or hyper advanced user who are willing to integrate or enhance Hibernate Search. Otherwise, they are considered APIs - which includes interfaces you might need to implement like FieldBridge. Hibernate ORM has a different semantic where an API is what the application directly code on.
I personally like the HSearch approach as it's clear when a change will affect common users. That's the proposal I have pushed to the common guidelines at JBoss.
For your second question, I have used the idea of an interface combined with an abstract class with success. The interface used by the consumers and the abstract class extended by implementors.
On 1 avr. 2012, at 12:44, Gunnar Morling wrote:
> Hi,
>
> related to my earlier mail on deprecations there's another thought I'd
> like to discuss.
>
> When evolving an SPI (typically *implemented* by clients), other
> restrictions apply than when evolving an API (typically *used* by
> clients). More specifically, it's no problem to add new methods to an
> API interface (existing clients continue to function without changes),
> while that's not true for SPI interfaces (existing implementations
> break).
>
> AFAIK there are basically two approaches for handling the evolvement of SPIs.
>
> One is to use use abstract classes instead of interfaces for SPI
> types. This allows to add new methods in future versions as long as a
> sensible default implementation in the abstract class can be provided.
> Implementation classes can override that default implementation if
> they want to.
>
> The other approach is to create a new interface extending the existing
> one in order to add new methods:
>
> public interface Foo {
> void bar();
> }
>
> public interface Foo2 extends Foo {
> void baz();
> }
>
> Clients implement the latest version they are aware of and want to
> support. For our own code this means that we have to perform some
> instanceof calls to determine the version of the passed SPI types.
>
> My question now is, whether you got any recommendations for this. Do
> you have any experience with either approach in other Hibernate
> projects?
>
> Thanks,
>
> --Gunnar
> _______________________________________________
> hibernate-dev mailing list
> hibernate-dev at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/hibernate-dev
More information about the hibernate-dev
mailing list