6. StarCraft PHP design mode-builder mode

Source: Internet
Author: User

Preface
==============================================================================
This PHP design mode album from the blog (jymoz.com), now has no access, this series of articles I have been looking for a long time to find the complete, thanks to the author Jymoz's Hard Pay Oh!

This address:http://www.cnblogs.com/davidhhuan/p/4248181.html
==============================================================================


There are a lot of missions in the star, you can also edit the map, the screen has a variety of terrain, construction and troops.
There is a problem, the process of initializing the screen is very messy.

problem to be solved: complete the work of the initialization screen while minimizing the coupling of various drawing details.

idea: Since the interstellar picture is made up of several parts: maps (terrain and minerals), buildings, troops. Then we look at them as parts and assemble them as the final product (the whole picture).

Builder Mode Example:

<?PHP//specification of interfaces for manufacturing individual parts    InterfaceBuilder {//Manufacturing Map Parts         Public functionBuildmappart (); //manufacturing of building parts         Public functionBuildbuildingpart (); //Manufacturing Force Parts         Public functionBuildarmypart (); //Assembling Parts         Public functionGetResult (); }    //the actual builder class, such as initializing a task off    classConcreteBuilderImplementsBuilder {//Manufacturing Map Parts         Public functionBuildmappart () {//draw a map based on the task's settings            Echo' Map parts \ n '; }        //manufacturing of building parts         Public functionBuildbuildingpart () {//draw the building according to the task's settings, including the player's and enemy's            Echo' Building parts \ n '; }        //Manufacturing Force Parts         Public functionBuildarmypart () {//draw the troops according to the task settings, including the player's and enemy's            Echo' Army parts \ n '; }        //Assembling Parts         Public functionGetResult () {//overlay and process everything to form an initialization screen            Echo' Assemble the parts \ n '; }    }    //supervised classes, which are classes that control the drawing process    classDirector {//private properties, determining which builder to use        Private $builder; //constructor method, parameter for the selected builder object         Public function__construct ($builder)        {            //determine the builder used            $this->builder =$builder; }        //The method of building the process, invoking the method of the builder object, making all the parts         Public functionBuildeallpart () {//Manufacturing Map Parts            $this->builder->Buildmappart (); //manufacturing of building parts            $this->builder->Buildbuildingpart (); //Manufacturing Force Parts            $this->builder->Buildarmypart (); }    }    //Let 's say we initialize the actual builder objects we need based on the task-off .    $concreteBuilder=NewConcreteBuilder (); //initialize a supervised object    $director=NewDirector ($concreteBuilder); //Manufacturing All parts    $director-Buildeallpart (); //finally let the builder assemble the parts and create the screen    $concreteBuilder-GetResult ();?>

Usage Summary: the builder mode separates the process from the details and performs its duties.

Implementation Summary: requires a builder interface or abstract class that is responsible for standardizing the various methods, such as the builder above. Then let the actual builder class implement all the methods, such as the concretebuilder above. Also need to be responsible for the process management of the supervision class, such as the above Director, responsible for invoking the builder of the various parts manufacturing methods. Finally, let the builder assemble all the parts.

Related articles:

1. StarCraft PHP Object-oriented (i)

2. StarCraft PHP Object-oriented (ii)

3. StarCraft PHP design mode-Simple Factory mode

4. StarCraft PHP Design mode-factory method mode

5. StarCraft PHP design mode-Abstract Factory mode

6. StarCraft PHP design mode-builder mode

7. The PHP design mode of StarCraft--The mediator mode

8. StarCraft PHP design mode--Enjoy meta mode

9. StarCraft PHP Design mode--proxy mode

10. StarCraft PHP design mode-prototype mode

11. The PHP design mode of StarCraft--Memo mode

12. StarCraft PHP design mode-template mode

13. StarCraft PHP design mode-positive mode

14. StarCraft PHP design mode-state mode

15. StarCraft PHP design mode--strategy mode

16. StarCraft PHP Design mode--combination mode

17. StarCraft PHP Design mode--responsibility chain mode

18. StarCraft PHP design mode-Observer mode

19. The PHP design mode of StarCraft--iterator mode

? 20. StarCraft PHP design mode-Adapter mode

6. StarCraft PHP design mode-builder mode

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.