简体   繁体   中英

Dart: inheritance and super constructor

My Dart app has the following class hierarchy:

abstract class AbstractPresenter {
    AbstractView view;

    AbstractPresenter(this.view);

    void start(EventBus eventBus) {
        view.presenter = this;
        querySelector("body").innerHTML = view.render();
    }
}

abstract class SigninPresenter implements AbstractPresenter {
    void onSignin(MouseEvent mouseEvent);
}

class DefaultSigninPresenter implements SigninPresenter {
    // Lots of code
}

abstract class AbstractView {
    AbstractPresenter presenter;

    AbstractView(this.presenter);

    String render();

    void bindUI(String html);
}

abstract class SigninView implements AbstractView {
    SigninView(AbstractPresenter presenter) : super(presenter);

    LabelElement getSigninLabel();

    void setSigninLabel(LabelElement signinLabel);

    InputElement getEmailTextField();

    void setEmailTextField(InputElement emailTextField);
}

class DefaultSigninView implements SigninView {
    LabelElement signinLabel;
    InputElement emailTextField;

    DefaultSigninView(SigninPresenter presenter) : super(presenter);

    // Lots of code...
}

The idea is to define a hierarchy of "views" and "presenters", where ultimately a DefaultSigninView will get related (bidirectionally) to a DefaultSigninPresenter .

But I'm getting a compiler warning in DefaultSigninView 's constructor, complaining about my call to super(presenter) :

Missing inherited member 'AbstractView.presenter'

Why can't it "see" the presenter I'm passing it? The parent constructor ( AbstractView ) takes an AbstractPresenter ...

This is because SigninView has not implemented all of the members of AbstractView. The same situation as your question here: Dart inheritance and super constructor

You are not extending AbstractView but implementing it. This means that you must implement a getter/setter for an AbstractPresenter presenter . Properties are not inherited if you only implement the class.

From the Dart language spec :

A class does not inherit members from its superinterfaces.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM