IOC, DI, DIP

OCP: opening and closing principle open for extension but closed for modification

1, object-oriented mainly do two things: instantiate the object and call the method (complete business logic)

2, simple interface you can call unified approach, but it can not be unified object instantiation

3, only a piece of code does not appear in the new, in order to maintain the relative stability of the code in order to gradually achieve OCP

To maintain a stable code, it should not instantiate an object

Examples of the isolation to other places

Examples of objects: the factory mode previously used (the abstract object, and each object instantiated separately) and reflected, and now the best IOC DI (maybe has not the same)

 

 JAVA reflection mechanism is in the operating state, for any class, are made known to all properties and methods of this class; for any object, are able to call any of its methods and properties; this information acquired dynamically and dynamic invocation function method object is called reflection mechanism of Java language. (Do not know)

 

Factory pattern is not reflected IOC and DI +

Factory pattern spring IOC also use the + reflective thought, but to better

IOC to create an object is created only once, and then into the cache

DIP: The Dependency Inversion details depend abstract (not important)

DI: dependency injection project is to produce object-oriented mutual interaction between objects, the role between the object and the object will certainly produce dependence, dependence is inevitable, but the way of dependence varied,

The most common way is a new object that is not good, because the new code indicating instability

Best of all objects created by the container and then injected into the object using the object's

The most commonly used properties is injected into the injection configuration and

 

 

 

 

Guess you like

Origin www.cnblogs.com/zhaobao1830/p/12080167.html