<?php /** **建造者模式:消除其他对象复杂的创建过程 *****/ class UserInfo{ protected $_age; protected $_name; protected $_prov; public function __construct(){ } public function setAge($age){ $this->_age = $age; } public function setName($name){ $this->_name = $name; } public function setProv($prov){ $this->_prov = $prov; } public function getMan(){ echo $this->_age.$this->_name.$this->prov; } } class Building{ protected $man = ‘‘; public function __construct(){ $this->man = new UserInfo(); } public function buildman($array){ $this->man->setAge($array[‘age‘); $this->man->setAge($array[‘name‘); $this->man->setAge($array[‘prov‘); } public function getman(){ $this->man->getMan(); } }
时间: 2024-10-11 21:08:55