Dependency Injection: Difference between revisions
Jump to navigation
Jump to search
Created page with "=Introduction= Dependency Injection or '''DI''' is when we provides the things we need into another object. <br> File:DI Intro.png <br> Originally in OO is was thought bet..." |
|||
Line 2: | Line 2: | ||
Dependency Injection or '''DI''' is when we provides the things we need into another object. | Dependency Injection or '''DI''' is when we provides the things we need into another object. | ||
<br> | <br> | ||
[[File:DI Intro.png]] | [[File:DI Intro.png| ]] | ||
<br> | <br> | ||
Originally in OO is was thought better to hide the internal objects and create them inside the object. | Originally in OO is was thought better to hide the internal objects and create them inside the object. | ||
<syntaxhighlight lang="kotlin"> | |||
class Car { | |||
Engine engine | |||
Wheels wheels; | |||
Car() { | |||
engine = new Engine() | |||
wheels = new Wheels() | |||
} | |||
void drive() { | |||
// chug chug | |||
} | |||
} | |||
</syntaxhighlight> |
Revision as of 01:08, 1 February 2021
Introduction
Dependency Injection or DI is when we provides the things we need into another object.
Originally in OO is was thought better to hide the internal objects and create them inside the object.
class Car {
Engine engine
Wheels wheels;
Car() {
engine = new Engine()
wheels = new Wheels()
}
void drive() {
// chug chug
}
}