[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

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。