开发者

What will make backward compatibility impossible?

We have a platform component (written in Java) that now shall be backward compatible for a certain period, e.g. 3 years. Is there a possibility, that implementing a new feature or fixing a bug must require an interface change in the platform?

One concrete example is, let's say there is some kind of listener interface defined in the platform, and the client code will implement the listener. Later a new method seems need开发者_如何转开发ed in the listener to introduce a new feature, but we cannot do that because it will break the interface so that some client will not be able to compile.

Is it a good idea to create a new interface that extends the original one with the new method? The client that needs this new feature will now implements the new interface, and other client code needs not to be changed. Of course the invocations in the platform shall now check the type of the listener, if it is the new interface with the new method, then the new method will be invoked, or nothing will be done.

This kind of change may make the code look not so straightforward, but I guess it shall still work. Are there any cases that an interface change in the platform is a must?


Is there a possibility, that implementing a new feature or fixing a bug must require an interface change in the platform?

Yes, if this bug is an accidental break of the backward compatibility and if you've released several versions (X+1 ... X+N) of the product before detecting this break. So, one part of your clients depends on older version X, but another part of clients depends on the X+1 ... X+N broken versions. And if you'll fix this bug, then newer clients (X+1 ... X+N) will be broken.

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

Possible, but you'll probably got a problem with naming of these interfaces and with documentation compilation. I recommend you to delay such features and break API each 3 years with supplying of detailed explanation of how to change old clients.

Of course the invocations in the platform shall now check the type of the listener, if it is the new interface with the new method, then the new method will be invoked, or nothing will be done.

There are 3 kinds of backward compatibility: binary (running old clients), source (recompilation of old clients) and behavioral. If you need to add a new method to the interface, then you can only break source compatibility but keep the binary compatibility by checking used interface version (final String VERSION = "N") and calling new method only for compatible versions. So, if some old client need a new feature, then it should be changed and recompiled.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜