PHP design pattern (factory pattern)

Your brother's way of programming (like to share) 2022-02-13 06:07:41 阅读数:789

php design pattern factory pattern

Factory.php

<?php
class Factory {

static function createDatabase()
{

$db=new Factory();
return $db;
}
}
var_dump(Factory::createDatabase());

The core is : If multiple files create this factory Object words , If you don't use this factory model , It will be modified many times , After using factory mode , Only modify this file once .
 Insert picture description here

copyright:author[Your brother's way of programming (like to share)],Please bring the original link to reprint, thank you. https://en.javamana.com/2022/02/202202130607391267.html