1 Factory model
BeanFactory, bean factory
Anyone who has used the spring framework should know that the objects in the container are not new. You can write the bean and inject it separately, or you can write the package path to scan the annotated method to inject it. The older ones are also reading configuration file injection. This is also the embodiment of Spring IOC, IOCtranslateyesControl reversal, control inversion refers to the right to create an object to the container to establish it. Therefore, when you use spring, you will no longer have new objects. Write annotations on the class, and then use @Autowired to find the container when using it. (Off topic: Then why do you do this? The answer is for decoupling. You don't need spring before writing logic. Maybe in the A method, you new object B, and then call the B method. There may be C, D, and EF later. The call is messy, and the readability and maintainability are very poor. Even if the code is written layered, Class B is a class that specializes in database query. Because it is a tool class that is tuned by others and does not remove others, it is best to make it a singleton. But there is also a C table that specializes in database insertion, which also needs to be made into a singleton. So does this singleton code have to be written every time, several lines of lazy and hungry men? However, after you use the spring bean factory, you can install it in the singleton factory and don't need to write singleton code. Singletons are managed by containers and are needed when using them. Cough, it’s like when you want to fall in love, you just look for the country and provide the distribution. Just imagine whether this is better managed for the entire society, reducing a lot of conflicts and reducing a lot of hidden contradictions. Of course this is impossible. Ethical issues cannot be considered too simple. Even if the country has resources, it cannot ensure that the distribution quality is uniform. Uneven distribution will cause new contradictions, and the contradictions may become even. Dissatisfied people may rely on the container and then break the container. But spring can guarantee that the objects allocated to spring are the same except for different addresses. In singletons, even the addresses are the same, which is equivalent to the object being public. )
2 Single casemodel
ApplicationContext , IOC container singleton bean
3 proxy mode
AopProxy, facet programming
4 Decorator Mode
BreanWrapper, properties and methods of accessing beans
5 Policy Mode
SimplelnstantiationStrategy, Bean's instantiation strategy
6 Adapter Mode
HandlerApdapter, Execute handler in SpringMVC
7 Observer Mode
ApplicationListener , Event Listening
8 templateMethod mode
JdbcTemplate, operation database template, AQS (abstract)queueSynchronizer) to solve the repetition of code