12. StarCraft PHP design mode-template 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/4248192.html
==============================================================================


The Zerg Army has a special evolutionary class, the Dragon, the dragon can become the Air guardian (day crab) or devour (empty). There is also the ability to evolve into a thorn in the mouth.
The three change processes are similar: the change of the original force disappears, producing an egg or cocoon, hatching for a while, the egg disappears, and the new army is produced.
If we were to separate these three evolutions, we would have duplicated code and increased redundancy, so we would try to reduce the extra code.

the problem to be solved: The same few steps are going through, but the details of each step are different.

idea: to be a framework for evolutionary engineering, we just have to control the details.

Sample template mode mode:

<?PHP//evolutionary Framework class, it's an abstract class .    Abstract classEvolution {//Framework method, which implements each step, with final prohibit subclasses from overwriting        Final  Public functionProcess$troop)        {            //generate an egg, parameters for the evolutionary force            $egg=$this->becomeegg ($troop); //wait for eggs to hatch, parameters for eggs            $this->waitegg ($egg); //generate new troops after hatching            return $this->becomenew ($egg); }        //the following three abstract methods are implemented by a specific subclass        Abstract  Public functionBecomeegg ($troop); Abstract  Public functionWaitegg ($egg); Abstract  Public functionBecomenew ($egg); }    //for the sake of simplicity, this is demonstrated by the evolution of the aerial defender (Tian Crab), the treatment of the ground thorn and so on, like//The evolutionary class of Tian crab inherits abstract Evolutionary class    classGuardianevolutionextendsEvolution {//implementation generates an egg         Public functionBecomeegg ($troop)        {            //destroy the Dragon, return the code of an Egg object        }        //waiting for eggs to hatch         Public functionWaitegg ($troop)        {            //Wait a few 10 seconds for the code        }        //generate new troops after hatching         Public functionBecomenew (($troop)        {            //destroy the eggs and return a day crab        }    }    //Create a new day crab, the evolutionary object.    $e 1=Newguardianevolution (); //Let it call the parent class's evolutionary framework function and automate three steps    $e 1->process ($sds);?>

Usage Summary: template mode automates a range of steps while satisfying different details.

Implementation Summary: an abstract class is required to contain the framework function, allowing the specific subclass to inherit it and implement all the steps. When used, the frame function is automatically completed as soon as it is called.

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

12. StarCraft PHP design mode-template 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.