Php has 23 Design Patterns. do you know all of them? The following code introduces the Builder mode (Builder mode )? Php * builder mode will be 1...
There are 23 php typesDesign ModeDo you all know? The following code is used to introduceBuilder mode (Builder mode)
"; $ This-> _ type = $ type;} public function setSize ($ size) {echo" set product size
"; $ This-> _ size = $ size;} public function setColor ($ color) {echo" set product color
"; $ This-> _ color = $ color ;}$ config = array (" type "=>" shirt "," size "=>" xl ", "color" => "red",); // no previous bulider processing is used $ oProduct = new Product (); $ oProduct-> setType ($ config ['type']); $ oProduct-> setSize ($ config ['size']); $ oProduct-> setColor ($ config ['color']); // Create a builder class ProductBuilder {var $ _ config = null; var $ _ object = null; public function ProductBuilder ($ config) {$ this-> _ object = new Product (); $ this-> _ config = $ config;} public function build () {echo "--- in builder ---
"; $ This-> _ object-> setType ($ this-> _ config ['type']); $ this-> _ object-> setSize ($ this-> _ config ['size']); $ this-> _ object-> setColor ($ this-> _ config ['color']);} public function getProduct () {return $ this-> _ object ;}} $ objBuilder = new ProductBuilder ($ config); $ objBuilder-> build (); $ objProduct = $ objBuilder-> getProduct ();
Other related design patterns:
Memorandum mode (Memento mode)
Observer Mode (Observer mode)
Template Method mode)
Command mode)
Composite mode)
Enjoy the metadata mode (flyweight mode)
Strategy mode)
State mode)
Adapter mode)
Factory mode)
Prototype)
Appearance mode (facade mode)
Singleton mode)
Bridge Mode)
Decorator mode)
Abstract factory mode (abstract factory mode)
Builder mode (Builder mode)
Visitor mode (Visitor mode)
Interpreter mode (Interpreter mode)
Mediator mode)
Responsibility Chain mode (Chain Of Responsibility mode)
Proxy mode)
Iterator mode)
Data Access Object mode (DAO mode)
Delegation mode)
Address:
Reprinted at will, but please attach the article address :-)