Pattern generator
require "D:\\xxx\bild.php"; require "D:\\xxx\cx_bild.php"; require "D:\\xxx\jt_build.php"; class Director { public function build($build){ $build->buildHeader(); $build->buildChiBang(); $build->buildJiao(); return $build->GetBird(); } } $dir = new Director(); $duixiang = $dir->build(newBuleBild ()); $ Zabild = $ dir -> build ( new Zabild ()); $ BuleBild = $ duixiang -> show (); $ Zabild = $ Zabild -> show ();
bild.php
<? PHP class Bild { public $ header ; public $ chibang ; public $ jiao ; function Show () { echo 'head of color'. $ The this -> header "<br>." ; Echo . 'Wing color' $ the this . -> chibang "<br>" ; echo . 'called color' $ the this -> jiao "<br>." ; } }
cx_build.php
<?php abstract class BildBuilder{ public $bild; public function __construct() { $this->bild = new bild(); } abstract function buildHeader(); abstract function buildChiBang(); abstract function buildJiao(); }
jt_build.php
<?php class BuleBild extends BildBuilder{ public function buildHeader(){ $this->bild->header = 'bule'; } public function buildChiBang(){ $this->bild->chibang = 'bule'; } public function buildJiao(){ $this->bild->jiao = 'bule'; } public function GetBird(){ return $this->bild; } } class Zabild extends BildBuilder{ public function buildHeader(){ $this->bild->header = 'Red'; } public function buildChiBang(){ $this->bild->chibang = 'huang'; } public function buildJiao(){ $this->bild->jiao = 'qings'; } public function GetBird(){ return $this->bild; } }