Вот есть у меня класс:
/**
* All classes that has super class [Fragment] by default must extend this class instead of [Fragment]
*/
abstract class BaseFragment(
@LayoutRes resId: Int,
) : Fragment(resId) {
protected open val navigator get() = requireActivity() as Navigator
protected open val sharedData get() = requireActivity() as SharedData
}
Можно использовать методы:
abstract class BaseFragment(
@LayoutRes resId: Int,
) : Fragment(resId) {
protected open fun navigator() = requireActivity() as Navigator
protected open fun sharedData() = requireActivity() as SharedData
}
Как лучше и почему?