What will make backward compatibility impossible?

We have a platform component (written in Java) that should now be backward compatible for a certain period of time, for example. 3 years. Is it likely that an interface change on the platform is required to implement a new feature or fix a bug?

One specific example: let's say there is some kind of listener interface defined in the platform, and client code implements a listener. Later, a new method is needed in the listener to present a new function, but we cannot do this because it will break the interface so that some client cannot compile.

Is it a good idea to create a new interface that extends the original with a new method? A client who needs this new feature will now have a new interface implemented, and the other client code should not be changed. Of course, calls on the platform should now check the type of listener, if this is a new interface with a new method, then a new method will be called or nothing will be done.

Such a change may lead to the fact that the code does not look so simple, but I think it will work anyway. Are there any instances of an interface change on the platform?

+6
source share
1 answer

Is it likely that an interface change on the platform is required to implement a new feature or fix a bug?

Yes, if this error is an accidental interruption of backward compatibility and if you have released several versions (X + 1 ... X + N) of the product before you discover this gap. Thus, one part of your customers depends on the old version of X, but another part of your customers depends on X + 1 ... X + N broken versions. And if you fix this error, new clients (X + 1 ... X + N) will be broken.

Is it a good idea to create a new interface that extends the original with a new method?

Perhaps, but you will probably have a problem with naming these interfaces and compiling the documentation. I recommend that you delay such features and terminate the API every 3 years, providing a detailed explanation of how to change old clients.

Of course, platform calls should now check the type of listener, if it is a new interface with a new method, then a new method will be called or nothing will be done.

There are 3 types of backward compatibility: binary (starting old clients), source (recompiling old clients) and behavioral . If you need to add a new method to an interface, you can only break the initial compatibility, but maintain binary compatibility by checking the version of the interface used (final String VERSION = "N") and calling the new method only for compatible versions. So, if some old client needs a new function, then it needs to be changed and recompiled.

+3
source

Source: https://habr.com/ru/post/891529/


All Articles