首页 > 代码库 > [php学习]工厂模式

[php学习]工厂模式

<?php/*** */class Automobile{	private $vehicle_make;	private $vehicle_model;	public function __construct($make,$model)	{		# code...		$this->vehicle_make = $make;		$this->vehicle_model = $model;	}	public function get_make_and_model(){		return $this->vehicle_make . ‘ ‘. $this->vehicle_model;	}}/*** */class AutomobileFactory{	public function create($make,$model){		return new Automobile($make,$model);	}}$veyron = AutomobileFactory::create(‘chuzha‘,‘love you‘);print_r($veyron->get_make_and_model());?>

值得注意的是调用静态方法:

AutomobileFactory::create

[php学习]工厂模式