如何处理一个 API 的两个版本 [英] How to deal with two versions of an API
问题描述
我的问题:处理两个不同版本的 API 的好方法是什么?(子问题:如果包含两个具有相同类名的库,有没有办法避免类路径引用问题?)
My Question: What is a good way to deal with two different versions of an API? (Sub-question: Is there any way to avoid classpath reference problems if you include two libraries with the same class-names?)
问题描述:我有一个使用 API 的项目.过去几个月我一直在为旧版本进行开发,我即将为新版本添加功能.据我所知,只有一个关键区别.但是,我还没有 API(等着有人给我拿 jar)所以我不能确定是否有更多的差异.
Description of question: I have a project that uses an API. I have spent the last few months developing for the old version and I'm about to add features for a newer version. So far as I can tell there's only one critical difference. However, I don't have the API yet (waiting on someone to get me the jar) so I can't be sure whether there are more differences.
子问题描述:我担心两个 API 之间可能存在类引用不一致(就像我说的,我还没有 jar 来确定).
Description of subquestion: I'm worried that there may be class reference inconsistencies between the two APIs (like I said, I don't have the jar yet to be sure).
我知道你可能想要看一些代码,但这是一个设计问题,而不是一个编码问题.我希望得到一些最佳实践.谢谢!
I realize you may want some code to look at, but this is a design question, not a coding issue. I'm hoping to get some best practices out of this. Thanks!
不是重复的:我查看一些问题似乎是重复的,但它们并没有真正解决我的问题:)
Not a duplicate: I've looked at a few questions which may appear to be duplicates, but they didn't really address my issue :)
推荐答案
避免或遮蔽.
如果您可以完全控制类路径,则可以使用排序:这是脆弱且不直观的.
If you have full control of the classpath you can use ordering: this is brittle and non-intuitive.
如果你不这样做,你就会受到任何事物的摆布,因此会出现阴影和相关的头痛.
If you don't, you're at the mercy of whatever is, hence shading, and its related headaches.
这篇关于如何处理一个 API 的两个版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!