? Php *** builder mode ** ------------- * Definition: separates the construction of a complex object from its representation, so that different representations can be created during the same build process. * Type: Create class mode * four elements: * 1: product class: generally a complex object * 2: Abstract builder: extracts the structure of complex product classes. Generally
? Php/*** builder mode ** ------------- * Definition: separates the construction of a complex object from its representation, so that the same build process can create different representations. * Type: Create class mode * four elements: * 1: product class: generally a complex object * 2: Abstract builder: extracts the structure of complex product classes. Generally
Name = $ name;} public function setType ($ type) {$ this-> type = $ type;} public function setPrice ($ price) {$ this-> price = $ price;} public function setColor ($ color) {$ this-> color = $ color;} public function show () {echo $ this-> name. ':'. $ this-> type. ''. $ this-> color. ''. $ this-> price; echo"
";}}// Abstract the creation process. It can be used to create interfaces Bulider {public function createType ($ type) and public function createName ($ name) for different objects ); public function createColor ($ color); public function createPrice ($ price); public function createCar ();} class ConcreteBulider implements Bulider {// contains a complex object public $ car; public function _ construct () {$ this-> car = new Car ();} public function createType ($ type) {$ this-> car-> setType ($ type);} public funct Ion createColor ($ color) {$ this-> car-> setColor ($ color);} public function createName ($ name) {$ this-> car-> setName ($ name);} public function createPrice ($ price) {$ this-> car-> setPrice ($ price );} public function createCar () {return $ this-> car ;}// encapsulate the variable-prone part, such as the sequence, attribute class Derictor {public function _ construct (ConcreteBulider $ bulider) {$ bulider-> createColor ('red'); $ bulider-> createName ('bmw '); $ bulider-> createPrice ('20140901 '); $ Bulider-> createType ('suv ');} class Client {public static function main () {// create a builder, the director class uses it to create an object $ bulider = new ConcreteBulider (); $ derictor = new Derictor ($ bulider); $ car = $ bulider-> createCar (); $ car-> show () ;}} Client: main () ;?>
The UML class diagram is as follows:
The builder mode is a creation mode used to create objects that are more complex than the product family. The first premise is that there is a complex object that abstracts the process of creating a complex object and is used to create other objects.
Statement: the builder contains a complex object that utilizes the component process of the complex object .. The director class is used to create an object that contains a builder object.