Dependency Injection: Difference between revisions

From bibbleWiki
Jump to navigation Jump to search
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|200px]]
[[File:DI Intro.png|400px]]
<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.

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
   }

}