Ioc/di control inversion and dependency injection

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.