简体   繁体   English

我应该扩展什么类,AcionBar或ActionBarImpl?

[英]What class should I extend, AcionBar or ActionBarImpl?

I feel this is a basic question wiht some trick. 我觉得这是一些技巧的基本问题。
I want to extend the functionality of ActionBar, upon looking up the ActionBar code it turns out ActionBar is an abstract class and the real instantiated class is ActionBarImpl. 我想扩展ActionBar的功能,在查找ActionBar代码后,事实证明ActionBar是一个抽象类,而真正的实例化类是ActionBarImpl。
This pattern of having an abstract and a Impl for implementation is widely used in android source code. 在Android源代码中广泛使用这种具有抽象和Impl的实现方式。
The developers site does not dwell in details, but always describes the abstract class as if it was the implemented class. 开发人员站点没有详细介绍,但始终将抽象类描述为已实现类。
I see that from the java language strict point of view I should extend ActionBarImpl, otherwise I will not be able to call super methods, but I have never seen an example out there extending the <class>Impl classes. 我从严格的Java语言角度来看,我应该扩展ActionBarImpl,否则我将无法调用super方法,但是我从未见过扩展<class>Impl类的示例。
Help. 救命。

The only difference between the abstract and implementation in this case is likely to be the abstract method(s). 在这种情况下,抽象和实现之间的唯一区别可能是抽象方法。 If the default behavior provided by the implementation class is acceptable, I'd say extend that and override the other methods you need. 如果实现类提供的默认行为是可以接受的,那么我可以说扩展它并覆盖您需要的其他方法。

If the abstract method behavior you want means you can't use the implementation at all, then extend the abstract class. 如果您想要的抽象方法行为意味着您根本无法使用实现,请扩展抽象类。

是的,您应该将Impl类扩展为扩展,因为如果扩展抽象类,则将必须提供抽象方法的实现,并且如果您不是要“更改”现有行为,而只是“扩展”或添加新行为,则可以更好地扩展Impl类。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM