简体   繁体   中英

Getters and Setters with interfaces has a parameter

How do i implement a getter and a setter method with interfaces as a parameter?

I have a class test that implements an Test interface but the interface has methods like this, that have other interfaces as methods.

public void setScoreStrategy(IScoreStrategy iScoreStrategy) {

}
public IScoreStrategy getScoreStrategy() {
    return null;
}
public ITestStatistics getTestStatistics() {
    return null;
}
public IQuestion getQuestion(int i) throws TestException {
    return null;
}

The same way you deal with the regular fields in class:

Assumingv you have scoreStrategy and testStatistics fields:

public void setScoreStrategy(IScoreStrategy iScoreStrategy) {
    this.scoreStrategy = scoreStrategy;
}
public IScoreStrategy getScoreStrategy() {
    return scoreStrategy;
}
public ITestStatistics getTestStatistics() {
    return testStatistics;
}
// ...

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