Skip to content

Instantly share code, notes, and snippets.

@bhavyakaria
Last active April 12, 2019 07:10
Show Gist options
  • Save bhavyakaria/a5ead7f26ed170d5f05c47e1b0b55f0d to your computer and use it in GitHub Desktop.
Save bhavyakaria/a5ead7f26ed170d5f05c47e1b0b55f0d to your computer and use it in GitHub Desktop.
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
}
@brunogirin
Copy link

setWheel should take a Wheel as an attribute rather than a Battery.

@bhavyakaria
Copy link
Author

I know its too late but thanks @brunogirin for pointing out the mistake.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment