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)