Skip to content

Instantly share code, notes, and snippets.

@ufocoder
Last active November 4, 2018 13:42
Show Gist options
  • Select an option

  • Save ufocoder/8b3997f2bde3a1ec8e34abef7bf9460e to your computer and use it in GitHub Desktop.

Select an option

Save ufocoder/8b3997f2bde3a1ec8e34abef7bf9460e to your computer and use it in GitHub Desktop.
class Car{
private Wheels wheel;
private Battery battery;
/*
Где-то в нашей кодовой базе мы инстанцирует объекты, требующие этот класс
Два варианта реализации внедрения зависимостей:
1. На основе конструктора
2. На основе setter-метода
*/
// На основе конструктора
Car(Wheel wh, Battery bt) {
this.wh = wh;
this.bt = bt;
}
// На основе setter-метода
void setWheel(Wheel wh){
this.wh = wh;
}
...
...
// Остальной код
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment