Last active
November 4, 2018 13:42
-
-
Save ufocoder/8b3997f2bde3a1ec8e34abef7bf9460e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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