Summary
Martin Fowler's classicArticle+ Transparent and brilliant translation + 1-2-3 UML illustrations (this is not enough to concern your teeth, huh, huh ).
Download Original Text
IOC container and dependency injection mode Martin Fowler, transparent translation, PDF format.
Good English friends can also read the original article inversion of control containers and the dependency injection pattern.
UML illustration
I drew UML diagrams for constructing subinjection, setting value injection, interface injection, and service locator. I wanted to insert them directly into the PDF file, but I thought this would affect the quality of the original text, after thinking twice, I decided to paste the image into the blog.
Use picocontainer to construct subinjection (page 5)
The yellow color class in the figure is a component written by Fowler and cannot be changed by his friends. The green color class can be added/modified by his friends.
The movielister and moviefinder class layers constitute the Strategy Mode. Movielister complies with the design principles for interface programming. Another good thing is that the client class movielistertester does not depend on the Implementation class (such as colonmoviefinder ). Dependencies on implementation classes are encapsulated in the configurecontainer () function.
Use spring for Value Setting Method injection (page 6)
The yellow color class in the figure is a component written by Fowler and cannot be changed by his friends. The green color class can be added/modified by his friends.
The movielister and moviefinder class layers constitute the Strategy Mode. Movielister complies with the design principles for interface programming. Another good thing is that the client class movielistertester does not depend on the Implementation class (such as colonmoviefinder ). Dependencies on implementation classes are encapsulated in a file called "Spring. xml.
Interface injection (page 7)
The yellow color class in the figure is a component written by Fowler and cannot be changed by his friends. The green color class can be added/modified by his friends.
The movielister and moviefinder class layers constitute the Strategy Mode. Movielister complies with the design principles for interface programming.
Note that although the colonmoviefinder instance is created in the ifacetester # configurelister () function, because only the injectfilename () function of injectfilename of the narrow interface is used, so there is still the potential to make ifacetester only dependent on the injectfilename interface.
Use service locator (page 8)
Sequence Chart
Toolbox
The UML diagram is drawn using the Visio 2003 + Pavel Hruby's uml2.0 template. The text part is typed using Google Pinyin input method.