要我向哪些类,AcionBar或ActionBarImpl?要我、AcionBar、ActionBarImpl

2023-09-12 22:04:33 作者:提刀杀红眼

我觉得这是一些室内用招一个基本的问题。 我想延长动作条的功能,在查找的动作条code原来的ActionBar是一个抽象类,真正的实例化类是ActionBarImpl。 有一个抽象的,一个默认地将Impl实施的这种模式被广泛应用在Android源$ C ​​$ C。 该开发者的网站没有住在细节,但总是描述抽象类,仿佛它是实现类。 我看到,从Java语言严谨的角度来看,我应该延长ActionBarImpl,否则我将无法调用的方法,但我从来没有见过一个例子在那里延伸在<类>默认地将Impl 类 帮助。

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. This pattern of having an abstract and a Impl for implementation is widely used in android source code. 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. 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.