Last active
April 12, 2019 07:10
-
-
Save bhavyakaria/a5ead7f26ed170d5f05c47e1b0b55f0d 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(Wheel wh){ | |
this.wh = wh; | |
} | |
... | |
... | |
// Rest of code | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
setWheel
should take aWheel
as an attribute rather than aBattery
.