Home>Article>Backend Development> What is factory pattern?
Factory pattern (factory pattern) is our most commonly used instantiation object pattern. It is a pattern that uses factory methods to replace new operations. The famous Jive forum uses the factory pattern extensively. The factory pattern can be seen everywhere in the Java program system. Because the factory pattern is equivalent to new for creating instance objects, we often generate instance objects based on class Class, such as A a=new A().
Factory mode is also used to create instance objects, so you need to be careful when doing new in the future. Can you consider using factory mode? Although doing so may require more work, it will bring problems to your system. Greater scalability and minimal modifications.
run();
As the project progresses, the bus class and the car class may "give birth to many sons", so we have to instantiate these sons one by one. What's worse, we may also have to instantiate the previous ones. The code is modified, such as modifying the class name or file name of the car or setting a constructor for the car or bus. If we do not use the engineering mode, we will need to modify the corresponding calling files and codes (forgot how to cause a bug!!) .
But if you consciously use the factory pattern from the beginning, these troubles will be gone.
The above is the detailed content of What is factory pattern?. For more information, please follow other related articles on the PHP Chinese website!