‫Are you ready to take your coding skills to a new advanced level?
‫You took the right decision.
‫Hello my friends, and welcome to Master Coding Family and the Complete Android Developer course.
‫In this tutorial, we will start a new series about the new advanced things, new advanced concepts
‫in Android Java and we will make a new course parallel course about the Kotlin.
‫We will start also with the Kotlin courses and this course we will be discussing dependency, injection
‫and advanced topics in Android and Java.
‫So if you are looking to be a professional Android developer and you didn't subscribe to our YouTube
‫channel, hit subscribe below and let us five stars on Udemy to get the latest tutorials and make this
‫course the biggest course on the earth.
‫Let's begin.
‫What is dependency injection?
‫In software engineering, a dependency injection is a technique whereby one object supplies the dependency
‫of another object.
‫A dependency is an object that can be used.
‫I think this is a Wikipedia definition, but I didn't understand it from the first 100,000 times I have
‫read it.
‫Just kidding.
‫It's a joke.
‫We will clarify everything in details.
‫So dependency or dependent means relying on something for support.
‫Like if I say I am relying too much on mobile phones, it means that we are dependent on them.
‫So we are dependent on them.
‫Our dependency is on mobiles.
‫What this means in Android and coding.
‫When a class A uses some functionality of class B, then it's said that said that the Class A has dependency
‫of class B.
‫Let's take a new a very quick example about dependency, the hard dependency we we have learned before
‫and learned in Java and we have learned and coded many times how to make that hard coded dependency.
‫I will go to the class.
‫I have created an app called Die App Dependency Injection App.
‫I will create a package just for clarifying.
‫I will name it as the I.
‫It's good.
‫I will create create a new Java class and I will name it as plain.
‫I will give you two example in this video in order to understand dependency injection.
‫And we will we will learn and we will work with the second example till the end of this series.
‫So start by the plain.
‫This class plain is I will define it as a plain.
‫If we have created as a plain, an object of plain depends on what a plain have a new component called
‫engine.
‫So the engine would be imported and would be embedded inside the plain.
‫So class plain depends on engine.
‫I need also a new class called wings
‫and dependency in also type.
‫I will name it a type engine type.
‫Okay.
‫We have created four classes.
‫The first one is the plain, which is the the one that have the engine wings and.
‫A type.
‫I will remove this.
‫A type I will name it as I will make a refractor for it.
‫I will name it type.
‫I will name it as type.
‫Okay.
‫Or plain type.
‫In order not to be confused with anything, plain type.
‫Okay.
‫So.
‫And if I have a properties in the engine, like in the horsepower,
‫if I have also and
‫something that we need to create for the engine like factory string as factory
‫and so on, I.
‫Well make also for the wings.
‫But till now, I will make them a empty.
‫Okay, guys, I need to clarify something.
‫Something before I will make them.
‫So if the plane.
‫If we go to the plane here, the plane, I will create a new engine object of it and create engine.
‫And it's empty constructor.
‫And the plane also contains wings w equal new wings.
‫Okay.
‫And type plane type.
‫Also a plane contains a plane type.
‫So t equal new plane type.
‫Okay.
‫Till now I didn't make anything responsible for or related for dependency injection.
‫It is just clarifying what we will do and and the previously created patterns for our code.
‫Okay.
‫So in this way we have.
‫Created the the the plane here.
‫And if I want to make a constructor.
‫Plane.
‫Public plane.
‫If I want, I can make it very fast insert and takes in parameter like this.
‫Okay.
‫So I will remove like this.
‫I will make them on the main activities.
‫So don't worry.
‫Every time I need to create a plan, I need to pass an engine wings and plane type objects.
‫Okay, this is the constructor.
‫I will go to the main activity and I will make a plane.
‫New plane.
‫So plane B equal new plane.
‫Okay.
‫There is an error, as we know here.
‫We need to pass the parameters for the constructor.
‫Change the nature of plane.
‫If we need to remove the signature of the constructor or we need to pass engine.
‫Wings and plane type.
‫So in order to make them here, I need to create an engine.
‫E equal new engine.
‫I need to create an instance of these classes also wings.
‫With w equal new wings.
‫And if I need to complete the the code, I need to create a type plane type plane type here t equal
‫new plane type.
‫This is the ordinary coding for our Java patterns.
‫Okay, so this is the way we have created plane P and if we have a method here called.
‫Public void
‫take off.
‫Okay.
‫It will make a toast Here.
‫Create a new toast.
‫This and taking
‫taking off.
‫Okay, so plane get this dot get context.
‫I will pass the context here.
‫Okay.
‫This is a class.
‫I cannot make them.
‫I will make a log I or V into.
‫Tag.
‫I will name it as tag and detecting a message called taking off.
‫Okay.
‫This is an ordinary thing that in Java we need to to display it and we have made it before.
‫So if we run the main activity.
‫In their emulator up front our application.
‫It's an ordinary application making a class called plane.
‫We are making an object of it, passing an engine object, wings object and type object plane type object
‫and calling the plane take off method.
‫If we run it, we have in the look at here and we search for tag we have the taking of method is working
‫fine because we have made it and everything is working fine.
‫Till now we didn't invent anything and we didn't have any dependency injection.
‫So we have.
‫Plain guys.
‫A concentrate on the topics and the and and the naming plain.
‫P has dependency on engine, plane type and wings.
‫Glasses.
‫So this is the main activity.
‫This is called a boiler plate code.
‫So what is a boiler plate and coding?
‫Boiler plate is any seemingly repeat repetitive code that shows up again and again in order to get a
‫result That seems like it's out to be much simpler.
‫So these are again and again we need to create them every time.
‫We need to create a plain object.