Ioc/di control inversion and dependency injection
The IOC and DI performance is the same as the effect of the object, with different names.
Let's use a realistic example to illustrate the effect of Ioc/di's performance.
, the small winter has a function of eating, dietitians ask for winter to eat potatoes, the process has a lot of limitations, that is, for the nutritionist, this dietitian can only request the winter, and also only eat potatoes, obviously a nutritionist can only give a person to go with nutrition, and then people can only eat potatoes, so obviously not! So make an improvement on this:
This time the dietitian can ask anyone with the ability to eat, as long as the ability to eat, that is, to achieve the ability to eat this person, you can be a nutritionist to ask, and also not just eat potatoes, any can eat food can be, is to achieve the ability to eat can be! So the dietitian can ask a lot of people to eat all kinds of food they want to eat.
For nutritionists, this process is called inversion of control, and for those who have the ability to eat it is called dependency injection.
In this performance process does not have this control reversal and the dependence injects two words the true meaning manifests, this is only a ioc/di performance effect.
Recent time is near, after some time to find a job, Qizaotanhei work time certainly more tight, later post hair will be slower!
Do not write code, say how the code is implemented, is to write two interfaces, an interface has to eat this method, the other interface is to eat this method, let everyone to achieve eat this interface, and people inside the preservation of food references, as member variables stored in each person (polymorphic), And let the various food realization be eaten this interface. The dietitian receives food through reflection, passes it on to the person being asked to eat, and thus achieves the purpose of controlling the reversal, and everyone waits to eat it, reaching the purpose of dependency injection!
It's written here, thanks for watching Astro Boy and the Little Meatball blog !
Ioc/di control inversion and dependency injection