spring教程学习3-依赖注入

依赖注入
public class TextEditor {
   private SpellChecker spellChecker;
   public TextEditor(SpellChecker spellChecker) {
      this.spellChecker = spellChecker;
   }
}

      比如说我有一个编辑器(TextEditor),现在需要在编辑器中实现拼写检查的功能,我们不需要知道具体的拼写功能怎么实现

那个可以交给其他人去实现,我们只需要在实例化的时候传入spellChecking即可

参考文章:w3school教程

猜你喜欢

转载自www.cnblogs.com/yanliang12138/p/9724990.html