简体   繁体   中英

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.
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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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