Design design Pattern C # language Description-builder (builder) mode
* This article refers to "Java and the pattern" part of the content, suitable for the design pattern of beginners.
The build pattern is the object's creation pattern. The construction pattern separates the internal representation of a product from the product's generation process, thus enabling a build process to produce a product object with a different internal representation.
A product often has a different composition as part of a product, which is often called the internal representation of a product. Different products can have different internal appearances, that is, different parts. Using construction mode allows customers to not know what parts of the product they are producing, what the respective parts of each product are, how it was built, and how to make the product. The following is an example of an implementation.
In this sample system, the end products product product is only two parts, namely Part1 and Part2. The corresponding construction methods also have two: BuilderPart1 and builderPart2. You can see that this pattern involves four roles:
Abstract Builder (Builder): An abstract interface is given to standardize the construction of various components of a Product object.
Concrete Builder (Concrete Builder): In this role are some classes that are closely related to applications that create instances of the product under the application's invocation.
Director (Director): is the role of dealing with the client, the creation of the product requirements are divided into the construction of each part of the request, and then delegate these requests to specific builders.
Product: An object in construction.
Builder:
public interface Builder
{
void BuildPart1 ();
void BuildPart2 ();
Product Retrieveresult ();
}//End INTERFACE DEFINITION Builder
ConcreteBuilder:
public class Concretebuilder:builder
{
Private product product;
public void BuildPart1 ()
{
Build the ' the ' of the ' product '
}
public void BuildPart2 ()
{
Build the second part of the product
}
Public Product Retrieveresult ()
{
return product;
}
}//End CLASS DEFINITION concretebuilder
Director:
public class Director
{
Private Builder Builder;
public void Director ()
{
}
public void construct ()//Product construction method, which is responsible for calling each part construction method
{
Builder=new ConcreteBuilder ();
Builder.builderpart1 ();
Builder.builderpart2 ();
Builder.retrieveresult ();
}
}//End CLASS DEFINITION Director
Product:
public interface Product
{
}//End INTERFACE DEFINITION Product
There is only one product class in the above system, and there is also a specific builder class. There are a number of product and builder types of the construction model as follows: