【发布时间】:2021-01-30 16:14:55
【问题描述】:
所以我知道依赖倒置代表了 SOLID 设计原则中的 D,我之前使用 SpringBoot 编写了一个 Web 应用程序,想知道这个代码示例是否显示了一个很好的依赖倒置原则的例子,或者没有帮助我正确理解这个概念。
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.validation.ObjectError;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;
import java.util.ArrayList;
import java.util.List;
/**
* Provides a set of methods for serving and handling Interview data.
*/
@Controller
@SessionAttributes(names = {"users"})
public class InterviewController {
private final InterviewAuditor interviewAuditor;
private final AthleteAuditor athleteAuditor;
/**
* Injects all the needed auditors to talk to the database.
*
* @param interviewAuditor - the interview Auditor.
* @param athleteAuditor - the athlete Auditor.
*/
@Autowired
public InterviewController(InterviewAuditor interviewAuditor, AthleteAuditor athleteAuditor) {
this.interviewAuditor = interviewAuditor;
this.athleteAuditor = athleteAuditor;
}
谢谢!
【问题讨论】:
标签: java spring spring-boot model-view-controller solid-principles