Design mode PHP5 implementation ---- Builder (Builder)

xiaoxiao2021-03-06  44

* /

/ *** Builder, explanation How to assemble * @Author doodoo * / interface builder {/ * * Create a part, such as a steering wheel of a car * / public function buildparta (); / * * * Create a part B, such as the wheel of the car * / public function buildpartb (); / ** * Create a C section, such as the car's engine * / public function buildpartc (); / ** * Get the product, ie car * / public Function getProduct ();

/ *** How to assemble? Specific objects * / class ConcreteBuilder implements Builder {public function __construct () {// do something} public function buildPartA () {// do something ...} public function buildPartB () {// do something ...} public function BuildPartc () {// do something ...} public function getProduct () {// Return to the results}}

/ *** Machinery ** is responsible for the completion of assembly, assembler know how to assemble ** @author doodoo * / class director {private $ builder = null; public function __construct (Builder $ Builder) {$ This-> builder = $ builder;} / ** * Make assembly * / public function construct () {$ this-> builder-> buildparta (); $ this-> builder-> buildpartb (); $ this- > builder-> buildpartc ();}}

/ *** Complex object * / interface product {}

// Test $ Builder = New Concretebuilder (); $ DIRECTOR = New Director ($ Builder);

// The object is assembled. $ DIRECTOR-> Construct (); $ product = $ builder-> getProduct ();

?>

转载请注明原文地址:https://www.9cbs.com/read-45336.html

New Post(0)