1. Scenario Mode
When discussing the factory method mode, I mentioned an application framework for exporting data, but I didn't discuss how to implement each method for exporting text. Now let's solve this problem.Assume that the exported file is divided into three parts, the file header, the end of the file, and the file body, regardless of the format.Document Header: Number of the branch or outlet, date of data exportEnd of file: outputFile body: Table NameExport data to text files and XML fil
Partial reprint: http://www.cnblogs.com/BeyondAnyTime/archive/2012/07/19/2599980.htmlA person who lives to be over 70 years old will experience several stages: baby, teenager, youth, middle age, old age. And everyone at each stage is certainly not the same ah, I think it can be said that there are no two people in the world in this 5 stages of life is exactly the same, but people who live to 70 years of age, have experienced these stages is certain. In fact, this is an example of a more classic
Design Mode note generator (Builder) mode Builder
// Builder mode --- object Creation Mode
/*
1: Intention: separates the construction of a complex object from its representation, so that different representations can be created during the same construction process.
2: Motivation
3: Applicability:
1> when creating complex objects, algorithms should be independ
Builder mode Definition: separates the construction of a complex object from its representation so that the same build process can create different representations.The builder pattern is a step-by-step creation of a complex object that allows the user to build them only by specifying the type and content of the complex objects. The user is not aware of the specifics of the build internals. The
Builder Mode
The builder model can separate the internal appearance of a product from the product generation process, so that a building process can generate product objects with different internal appearances.
Object Construction
In some cases, an object has some important properties and cannot be used as a complete product until they have no proper values. For example, an email contains the send
Builder pattern Definition: Separates the construction of a complex object from its representation, allowing the same build process to create different representations.
The builder pattern is a step-by-step way to create a complex object that allows users to build them only by specifying the type and content of complex objects. The user does not know the specific build details inside. The
The builder pattern is somewhat similar to the previous abstract factory pattern, but more powerful than the abstract factory pattern, the builder pattern can be seen as two parts, one builder, and the other is that the basic idea of Director,builder is the abstract factory, While the director exists to make the use of
Idea: Since the interstellar picture is made up of several parts: the map (the terrain and the minerals), the building, the troops. Then we think of them as parts, assembled to be the final product (the whole picture).
Builder (Builder) mode example:
The code is as follows
Copy Code
Specification of interfaces for manufacturing individual parts Interface
Design Patterns ----Builder ( builder ) Mode
GoF : separates the build of a complex object from its representation, allowing the same build process to create different representations.
The builder mode is very much like the Absrtact Factory mode. Gof points out that the main difference between the two is that the builde
Design Pattern Series (iii) the factory model is described in the article, the factory method model and the abstract factory pattern are introduced. This paper mainly introduces the design pattern of builderOverviewIn the software system, sometimes faced with the creation of "a complex object", it is usually composed of the child objects of each part by a certain algorithm; Because of the change of requirements, the various parts of this complex object often face drastic changes, but the algorit
Reference 1:http://en.wikipedia.org/wiki/builder_patternReference 2:http://www.cnblogs.com/devinzhang/archive/2012/01/06/2314670.htmlBuilder mode executes and returns the result of a constructed object to a large number of constructors, step-by-step. The intent of the Builder design pattern is toseparate the construction of a complex object from its representation. B Y Doingso the same construction process can create different representations. The str
Use Builder mode to build a car, and builder mode to build a car
Builder mode can also be used for car creation.
For the Builder model, the prime minister wants to determine the car to be built:
public class Car { public string Model { get; set; } public string Engine { get; set; } publ
There are many examples of builder in life, and personally feel that college life is the best experience of a builder model: to complete a university education, the university education process is generally divided into 4 semesters, so no study can be seen as a part of the construction of a complete university education process, Each person has a different final result after the 4-year (4-phase) build proce
Separating a complex build from its presentation allows the same build process to create different representations. [Construction and presentation separation, different representations of construction]The difference from the abstract factory: in the builder model, there is a mentor who manages the builder, the user is in contact with the mentor, and the mentor contacts the
The factory class pattern provides the pattern of creating a single class, while the builder pattern is to centralize the various products to manage, to create composite objects, so-called composite objects that refer to a class that has different properties, in fact the builder pattern is the combination of the previous abstract factory pattern and the last Test. Let's look at the code:As before, a sender
The builder pattern is defined in design mode as a pattern for building complex objects that often require multiple-step initialization or assignment to complete. So, in the actual development process, where do we fit the builder model? It is a good practice to use builder mode instead of multi-parameter constructors.We often face the writing of such an implement
In fact, the builder pattern is to create an inner class in the class and then the outer class constructor passes the pair image of an inner class, and then the return value in the set and get methods in the inner class is an internal class pair image, which makes it possible to implement the builder pattern well. In fact he is like StringBuilder in the append:string a= "a"; A.append ("Wo"). Append ("Shi").
When writing a popup, it can include the OK button, the Cancel button, the title bar, the Close button, the Minimize button, the content, the Maximize button and so on, but the content does not have to exist under different requirements, different requirements need to be free to mix these components, obviously each combination must be repeated coding. Separating these different, easy-to-change components and constructing complex objects step-by-stage with a
Builder mode builder
Introduction:For Android, the Builder design mode may be rarely used in our development, but we may have seen that AlterDialog. Builder is a Builder mode. So what is the builder model? Let's take a look at its
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.