Alibabacloud.com offers a wide variety of articles about spring factory pattern injection, easily find your spring factory pattern injection information here online.
The two often come together, or they are often used together. But in fact it is divided into two situations:1 simultaneous use of Factory-bean and Factory-methodIf we configure Factory-bean and factory-method on a bean element at the same time, then it means that the bean is created using the
Java design pattern (1) simple factory pattern is not simpleSimple factory Use Cases
There is an abstract product-Car, and there are a variety of specific sub-products, such as BenzCar, BMWCar, and LandRoverCar. The class diagram is as follows:
As a driver, if you want to drive one of them, such as BenzCar, the most di
The introduction recently saw a video explaining the. NET design pattern in Youtub, where one of the authors ' understandings impressed me deeply: the so-called design pattern is actually using object-oriented programming to solve the problem of tight coupling and low expansion in peacetime code. Another point of view is that the design pattern is differentiated,
think that if we add a subclass implementation, then shapefactory must modify the source code, and recompile, this is not the result we want. If you can not change the content of the shapefactory, but will be called to write the subclass in the configuration file, so that Shapefactory received from the configuration file needs to return the subclass name, return the corresponding subclass instance. Here, you may sound familiar, this is not very similar to the dependency
to create the instance of the caller, that is, a new called object. In Spring, the creation of the called object is not completed by the caller.Control reversalThe creation of the called instance is completed by the Spring container and then injected to the caller.Dependency Injection.
Spring uses the configuration f
"Factory-method= "Getcar"> Constructor-argvalue= "BMW">Constructor-arg> Constructor Injection - Bean> Configure an instance of the factory - BeanID= "Instancefactory"class= "Com.test.spring.factorybean.InstanceFactory">Bean> configuring beans through the instance
Classification of plant design and design patterns: The factory model is divided into three categories in Java and mode:1) Simple Factory mode (simply Factory): not conducive to the production of products;2) Factory method mode (Factory): Also known as the polymorphism plant
axe (the caller) to find factories, buy axes, do not care about the manufacturing process of the axe; corresponding to a simple factory design pattern, callers need to locate the factory without having to manage the specific implementation of the calleeTo enter the "Communist" society, people who need an axe do not even have to locate the
Configuring a factory bean is usually created by the application using new, and in order to separate the creation and use of the object, the factory pattern is used, where the application takes the creation and initialization responsibility of the object to the factory object. In general, the application has its own
races), define the public interface of the specific product;Step 4: Create specific product classes (inherit abstract product classes) Define specific products for production;Step 5: Create a specific factory class (inherit abstract factory Class), define the method to create the corresponding product instance;Step 6: The client creates an instance of a different product class by instantiating the specifi
Definition: Provides an interface that creates a series of related or interdependent objects without specifying their specific class.ConceptTo understand the abstract factory model, first understand a few concepts, one is the product hierarchy, the other is the product family.The factory hierarchy is introduced in the factory method mode , which solves the proble
to create and inject the external resources required by the application;
Control reversal: The container controls the application, and the container reversely injects the required external resources into the application.4.2 relationship between factory method mode and IOC/di
As mentioned above, with IOC/di, applications no longer take the initiative, but passively wait for containers to inject resources. When writing code, once external resources are
instantiate it by reflection. The opening of the extension is achieved, while the closure of the modification is ensured. Readers familiar with spring should think of the spring IOC implementation.Annotations make simple Factory mode not simpleIn the example above, the reflection was used to open the extension and close the modification. Sometimes, however, it i
How to Implement spring injection and spring InjectionHow to Implement spring Injection
IOC (Inverse of Control) can be translated as "Control inversion", but most people are used to calling it "dependency injection ". In
. The ax is no longer done by ordinary people, but is produced in the factory. At this time, the ax user (caller) needs to find the factory and buy the ax, so there is no need to care about the production process of the ax. Corresponds to the design pattern of the simple factory of Java program.
(3) In the "pay-as-you-
, if you need to collaborate with another object (call its method and access its attributes), you do not need to create the called user in the code, it depends on the injection of external containers. Spring dependency injection has almost no requirements on callers and callers. It fully supports the management of dependencies between POJO.
Dependency
specific implementation between objects is transparent to each other. Before understanding dependency injection, let's look at how this problem can be solved in various social forms: a person (Java instance, caller) needs an ax (Java instance, called ).(1) there is almost no social division of labor in the primitive society. The caller can only sharpen an ax by himself ). The corresponding scenario is: the caller in the Java program creates the calle
lifecycle of the seam context (for example@ Destroy). Therefore, seam context can accommodate non-seam component objects, and seam provides some good features, which make it easier to deal with non-Component Objects bound to the context.
Factory component pattern (factory Component Mode)Make the seam component a constructor for non-component objects. When the
. The ax is no longer done by ordinary people, but is produced in the factory. At this time, the ax user (caller) needs to find the factory and buy the ax, so there is no need to care about the production process of the ax. Corresponds to the design pattern of the simple factory of Java program.
(3) In the "pay-as-you-
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.