Which base fragment prefer to use and why? In this implementation layoutRes is abstract field.
abstract class BaseFragment1 : Fragment() {
abstract val layoutRes: Int
override fun onCreateView(inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View {
return inflater.inflate(layoutRes, container, false)
}
}
And in this implementation layoutRes is passing through constructor
abstract class BaseFragment2(@LayoutRes private val layoutRes: Int) : Fragment() {
override fun onCreateView(inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View {
return inflater.inflate(layoutRes, container, false)
}
}
I want to know which implementation is better to use? If you have another solution you can share it. Example of implementations:
class FramgnetA : BaseFragment1() {
override val layuotRes = R.layout.layout
}
class FragmentB : BaseFragment2(R.layout.layout)