1. Factory methods or classes generate objects instead of new directly in the code.
2. When the class name corresponding to the object changes, you only need to change the instantiation method in the factory class. No need to change everything externally.
Define a class specifically for creating other objects. In this way, when we need to call a certain class, we do not need to use the new keyword to instantiate it, but call a certain method through our factory class to obtain an instance of the class.
Example
classFactory{ static function createDatabase(){ $db =new Database(); return $db; } } $db=Factory::createDatabase();
The above is the use of php factory mode, I hope it will be helpful to everyone. More PHP learning guide: source code network