What class should I extend, AcionBar or ActionBarImpl?

跟風遠走 提交于 2019-12-14 04:05:29

问题


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.


回答1:


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.




回答2:


Yes, you should extend the Impl class for extensions, because if you extend the abstract class, you will have to provide the implementation of abstract methods and if it is not your intention to "change" the existing behavior but only to "extend" or add new behavior then you better extend Impl class.



来源:https://stackoverflow.com/questions/17644881/what-class-should-i-extend-acionbar-or-actionbarimpl

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!