[英]Runtime determination of base class
I have two OS dependent base classes - Class A and Class B in the form of separate jars. 我有两个依赖于OS的基类-单独的jar形式的Class A和ClassB。
Before N OS, the behavior was --> Class C extends Class A. 在N OS之前,行为是-> C类扩展了A类。
Now, the behavior that is required is: 现在,所需的行为是:
Till Android M: Class C extends Class A. 直到Android M:C类扩展了A类。
For Android N and above: Class C extends Class B. 对于Android N及更高版本:C类扩展了B类。
What would be the most efficient way of doing this? 最有效的方法是什么?
Come up with a common interface that covers the functionality that A
and B
provide, and write adapters between this interface and the two said classes. 提出一个涵盖A
和B
提供的功能的通用接口,并在该接口与两个所述类之间编写适配器。 Then compose the appropriate adapter into your C
class. 然后将适当的适配器组合到您的C
类中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.