-
-
Save girisagar46/5f050a7dbff1b72ae65a4595fc410fd7 to your computer and use it in GitHub Desktop.
This file contains 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; | |
/*Somewhere in our codebase we instatiate the objects required by this class. | |
There are two methods for implementing DI: | |
1. Constructor based | |
2. Setter based | |
*/ | |
// Constructor Based | |
Car(Wheel wh, Battery bt) { | |
this.wh = wh; | |
this.bt = bt; | |
} | |
// Setter Based | |
void setWheel(Battery bt){ | |
this.bt = bt; | |
} | |
... | |
... | |
// Rest of code | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment