What the hell this Dependency Injection?

What is Dependency Injection? 💉🤔  

introduction

Before come to the topic Dependency injection we will look How to build softwares with the Engineering principles. Software engineering it's all about the requirements, memory management and performance. So whenever we start build, we should consider above factors. So here specially we will focus about memory management. 

If we start to build any simple application. initially it's easy maintain but when things get complicated it's hard to understand, maintain and Test. so before we start to build any system from the best practices. we should consider all things.

I'm taking an example from https://developer.android.com/training/dependency-injection  to understand the Dependency injection. 

 



Car is depending on Engine and Wheels to work, so Engine and Wheels are the dependency on the Car. So consider the below the code


 public class Car {  
   private static final String TAG = "Car";  
   
   private Engine engine;  
   private Wheels wheels;  
   
   public Car(Engine engine,Wheels wheels)  
   {  
     this.engine=engine;  
     this.wheels=wheels;  
   }  
   
   public void drive()  
   {  
     Log.d(TAG, "driving");  
   }  
   
   
 }  

a

Comments

Popular posts from this blog