IOC mode introduces IOC full name Inversion Of Control, is one of the founders of Apache Avalon project, and Stefano Mazzocchi is proposed, which mainly emphasizes the design security. What is the IOC mode in this mode, Framework played the role of the main program, responsible for coordinating events and applications. The designer creates a chain in the object, all objects on the chain can be in response to a message of certain format in a manner. IOC (flip control) has a language detail, that is, the parent object control sub-object. As can be seen from this point, the SAX API cannot count IOC because its purpose is to send information from the source to a processor. Note: Delegation, ClassLoader in Java is a proxy mechanism that uses a class. When a class is class, let's let the Parent Class Loader go to Load. Only when the parent class can't load, try itself Load similar definition: there are some similar But different concepts can help you understand the IOC mode. A similar example is a Chain of Command in the army. This may be the most similar example. The army provides them with the basic equipment required by each recruiting level, and issues the commands that the recruit must be observed. The same rule can be applied to programming. Each component (component component "is initialized entity (Instantiating Entity, commander in the army) specifies the need to implement. Initializing entities can manipulate these components and tell them how to do it. In this class, there are some places that don't quite the same. In the army, as long as the level is higher than yourself, the commander can send a single order, but in the programming, you will definitely not hope This is the case. How to apply: IOC applications are very simple, basically the component architecture uses a passive structure, see the following code:
Class mycomponent
Implements Logenabled
{
Logger logger;
Public Enablelogging (Logger NewLogger)
{
THIS.LOGGER = Newlogger;
}
mymethod ()
{
Logger.info ("Hello World!");
}
}
MyComponent's parent class initializes myComponent, sets the logger, and call the MyMethod method. Components are not autonomous, he accepted the parent class to the Logger object configured by the parent class.
MyComponent classes do not have any status from the parent class, and if there is no parent class to send him, it is not possible to get a reference to a Logger.