gpt4 book ai didi

java - 为什么 Base FragmentActivity Honeycomb 是抽象的?

转载 作者:行者123 更新时间:2023-12-01 09:03:22 26 4
gpt4 key购买 nike

为什么android.support.v4.app.BaseFragmentActivityHoneycomb在实际上没有任何抽象方法的情况下被声明为抽象?我知道他们不希望任何人实例化 BaseFragmentActivityHoneycomb,但为什么他们不直接编写 BaseFragmentActivityHoneycomb 的方法 onCreate() 的内容> 在 FragmentActivity 内?

这只是历史或偶然,还是有良好的设计 Intent ?

最佳答案

why don't they just write the content of the method onCreate of BaseFragmentActivityHoneycomb inside FragmentActivity?

我只能推测,他们正在减少 FragmentActivity 尝试遵循 SOLID programming 中的单一责任原则的关注点数量。 。

让我们看一下 BaseFragmentActivityHoneycomb 的代码:

@Override
public View onCreateView(View parent, String name, Context context, AttributeSet attrs) {
final View v = dispatchFragmentsOnCreateView(parent, name, context, attrs);
if (v == null && Build.VERSION.SDK_INT >= 11) {
// If we're running on HC or above, let the super have a go
return super.onCreateView(parent, name, context, attrs);
}
return v;
}

虽然将其作为一个 block 包含在子类的 onCreate 中似乎很简单,但 FragmentActivityonCreate() 方法是已经有 37 行长了。如果与 Honeycomb 兼容性相关的特定功能位于其自己的隔离类中,则维护程序员更容易理解。

关于java - 为什么 Base FragmentActivity Honeycomb 是抽象的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41493238/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com