"Unity3d and 23 design Modes" Builder mode (builder)

Source: Internet
Author: User

Defined in Gof:

"Separating a complex build process from its object representation allows the same build process to produce different object behavior." ”

The builder model can be divided into two steps to implement:

1. Separate the complex build process and divide the entire process into several steps, each of which can be either a functional component setting or a parameter designation, and in a build method, these steps are strung together.

2. Define a specific implementation of these steps, who know how each part should be done, and can accept parameters to determine the function to be produced, but do not know what the entire assembly process is.

GRASP two principles: "Process Analysis arrangement" and "function separate realization"

 Public Abstract classbuilder{ Public Abstract voidBuildPart1 (Product theproduct);  Public Abstract voidBuildPart2 (Product theproduct);} Public classconcretebuildera:builder{ Public Override voidBuildPart1 (Product theproduct) {Theproduct.addpart ("Concretebuildera_part1"); }     Public Override voidBuildPart2 (Product theproduct) {Theproduct.addpart ("Concretebuildera_part2"); }} Public classconcretebuilderb:builder{ Public Override voidBuildPart1 (Product theproduct) {Theproduct.addpart ("Concretebuilderb_part1"); }     Public Override voidBuildPart2 (Product theproduct) {Theproduct.addpart ("Concretebuilderb_part2"); }} Public classproduct{Privatelist<string> M_part =Newlist<string>();  PublicProduct () {} Public voidAddpart (stringPart )    {M_part.add (part); }     Public voidshowproduct () {foreach(stringPartinchM_part)        {Debug.Log (part); }    }}
// Test Class void UnitTest () {    new  Director ();     NULL ;        Thedirector.construct (new  Concretebuildera ());     = Thedirector.getresult ();    Theproduct.showproduct ();        Thedirector.construct (new  Concretebuilderb ());     = Thedirector.getresult ();    Theproduct.showproduct ();}

The article is compiled from the book "Design pattern and game perfect development" dishes rise up

"Unity3d and 23 design Modes" Builder mode (builder)

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.