[英]Use classes from a library's library?
Let's say I have a LibImplementationA
that includes a LibInterfaces
. 假设我有一个
LibImplementationA
,其中包含LibInterfaces
。
LibImplementationA
contains the implementations of LibInterfaces
's java interfaces . LibImplementationA
包含LibInterfaces
的java接口的实现。
My application uses the interfaces from LibInterfaces
and the implementations from LibImplementationA
. 我的应用程序使用的接口
LibInterfaces
,并从实现LibImplementationA
。
I included LibImplementationA
in my app, and I thought I could use the interfaces from LibInterfaces
in my app's code. 我在我的应用程序中包括了
LibImplementationA
,我认为我可以在我的应用程序代码中使用LibInterfaces
的接口。 But I couldn't ! 但是我做不到!
Why ? 为什么呢
To make my app work, I must include LibImplementationA
and LibInterfaces
. 要使我的应用正常工作,我必须包含
LibImplementationA
和 LibInterfaces
。
So LibInterfaces
is duplicated (in LibImplementationA
and my app), and this seems really bad (in case of the update of LibInterfaces
) 因此,
LibInterfaces
是重复的(在LibImplementationA
和我的应用程序中),这似乎真的很糟糕(在LibInterfaces
更新的情况下)
Last but not least, in my app I want to be able to switch from using LibImplementationA
to LibImplementationB
or LibImplementationX
(that's why the app uses LibInterfaces
). 最后但并非最不重要的一点是,在我的应用程序中,我希望能够从使用
LibImplementationA
切换到LibImplementationB
或LibImplementationX
(这就是该应用程序使用LibInterfaces
的原因)。
My real problem is way more complex, but I need a clever idea to avoid duplications of this LibInterfaces
, if possible! 我真正的问题是要复杂得多,但是我需要一个聪明的主意,以避免可能的
LibInterfaces
重复! I'm using Android Studio, with gradle. 我正在使用带有gradle的Android Studio。
Edit: for a better understanding, LibInterfaces
contains communication interfaces (as simple as sendMessage()
, messageReceived()
methods) and LibImplementationX
implements those methods using SIP, XMPP, WebSocket, Whatever. 编辑:为了更好地理解,
LibInterfaces
包含通信接口(如sendMessage()
, messageReceived()
方法一样简单sendMessage()
,并且LibImplementationX
使用SIP,XMPP,WebSocket和其他方法实现这些方法。
“为什么”的答案LibInterfaces
可以被保护/默认作用域接口,并且不能在该特定程序包之外实现。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.