$this->userAge = $userAge; } public function setUserMoney($userMoney) { $this->userMoney = $userMoney; } public function getPeople() { echo "Name is:" . $this->userName . ",Age is:" . $this->userAge . ",Money is:" . $this->userMoney; } } $peopleInfo = array('userName' => 'name', 'userAge' => '12', 'userMoney' => '1200'); $UserInfo = new UserInfo(); //下面需要一步步的设置用户信息,才能得到用户详细信息,过程纠结而痛苦 $UserInfo->setUserName($peopleInfo['userName']); $UserInfo->setUserAge($peopleInfo['userAge']); $UserInfo->setUserMoney($peopleInfo['userMoney']); $UserInfo->getPeople(); /** * 消除对象复杂创建的过程 */ class UserInfoBuilder { protected $obj; function __construct() { $this->obj = new UserInfo(); } public function buildPeople($peopleInfo) { $this->obj->setUserName($peopleInfo['userName']);