Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/205.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/design-patterns/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何使用my BasePresenter扩展所有视图_Android_Design Patterns_Kotlin_Mvp - Fatal编程技术网

Android 如何使用my BasePresenter扩展所有视图

Android 如何使用my BasePresenter扩展所有视图,android,design-patterns,kotlin,mvp,Android,Design Patterns,Kotlin,Mvp,我在一个项目上工作,并对其进行mvp,现在,我的所有活动都有一个BaseActivity和一个BasePresenter,它与我所在活动的视图一起工作,这样做是为了在与我的presenter一起工作时附加、编辑并知道我的视图是否为空 现在,对于我的第一个观点来说,这很好 abstract class BasePresenter<T : LoginContract.View> : Presenter<T> { private var mMvpView: T? =

我在一个项目上工作,并对其进行mvp,现在,我的所有活动都有一个BaseActivity和一个BasePresenter,它与我所在活动的视图一起工作,这样做是为了在与我的presenter一起工作时附加、编辑并知道我的视图是否为空

现在,对于我的第一个观点来说,这很好

abstract class BasePresenter<T : LoginContract.View> : Presenter<T> {

    private var mMvpView: T? = null

    val isViewAttached: Boolean
        get() = mMvpView != null

    override fun attachView(view: T) {
        mMvpView = view
    }

    override fun detachView() {
        mMvpView = null
    }
}
但我想知道是否有一种方法可以像这样扩展多个视图

class LoginPresenter: BasePresenter<LoginContract.View>(), LoginContract.Presenter {

....
abstract class BasePresenter<T : multipleViews> : Presenter<T> {
抽象类BasePresenter:Presenter{

您不能扩展多个类。您应该使用一些基本接口

你怎么能做到这一点
  • 基本演示者可以使用一些
    BaseView
    界面:
  • 现在您可以在GeneralPresenter中使用它了
  • 类GeneralPresenter:BasePresenter
    
    你不能像对待BasePresenter那样创建一个基本视图,并用它替换LoginContact.View吗?
    abstract class BasePresenter<T : multipleViews> : Presenter<T> {
    
    abstract class BasePresenter<T : BaseView> : Presenter<T>
    
    interface AllViews: LoginContract.View, RegisterContract.View
    
    class GeneralPresenter : BasePresenter<AllView>