Old saying: builder mode (how far is the design mode from us)

Source: Internet
Author: User
Design Mode This word is both literally and in a specific sense and has a distinctive temperament. Design And Mode It is a sufficient word.

 

Glossary:Imported from Baidu

 

Design:

Humans transform the world through labor, create civilization, and create material wealth and spiritual wealth. The most basic and main creative activity is creation. Design is a pre-planning of the creation activity. It can understand the planning technology and planning process of any creation activity as design. It refers to creative activities with goals and plans.

 

Mode:

Abstract and sublimation of previous experiences. Simply put, it is a summary of the experience in solving problems by discovering and abstracting patterns from repeated events. As long as it appears repeatedly, there may be a pattern.

 

When I hear that others are engaged in design, they are very admired. Whether it is the IT industry or not, I feel that the design can always start from the global perspective and consider the problem in a balanced manner, it is always a little higher than the bottom-layer workers.

 

ProgramMembers want to write their own programsCodeThe architecture is strong, easy to maintain, and highly scalable. The design model may be the best theory to achieve this idea. so many programmers (including myself) want to have a little bit of design patterns in their own programs, even if the role is not so obvious, there will be a sense of accomplishment. however, not all programmers can easily find such an opportunity. Although the 23 modes are clearly defined, they do not know how to use them in specific projects.

 

Another scenario is that when you are not very clear about all the concepts of the design model, suchBuilder ModeTheir programs often apply to a certain mode, but they do not care much about it. stringbuilder in. Net applies the builder mode.

 

In my experience, I used to develop a paging control in a project. However, after learning the builder mode, I found that it was an application mode.

 

We know that all controls, including user controls and custom controls, are inherited fromControlClass. In the custom control, I override the following methods:

 

Code
// Override the output tag of the server control
Protected   Override Htmltextwritertag tagkey
{
Get
{
ReturnHtmltextwritertag. div;
}
}

// Override the event before the server control content is output
Protected   Override   Void Onprerender (eventargs E)
{

// Paging style table information
If ( ! This . Custompager. iscustomstyle)
{
This. Addstylefile ();

}
Base . Onprerender (E );
}
// How to override the output content of the server control
Protected   Override   Void Rendercontents (htmltextwriter output)
{
// If (designMode)
// {Return ;}

// Write paging information
This . Csgetpagerhtml ( This . Custompager. irecordcount, This . Custompager. irowscount, output );
Page. verifyrenderinginserverform ( This );




}
/**/ /// <Summary>
///Widget loading event
/// </Summary>
/// <Param name = "E"> </param>
Protected   Override   Void Onload (eventargs E)
{
Querystring = Page. Request. servervariables [ " QUERY_STRING " ];
Currenturl = Page. Request. path;
Int I = 0 ;
If ( This . Custompager. urlpaging = True   &&! DesignMode)
{

If ( ! Page. ispostback)
{
Int Index;
Int . Tryparse (page. Request. querystring [ This . Custompager. urlpageindexname], Out Index );
If (Index <=   0 )
Index =   1 ;
If (Index > This . Pagecount)
{Index=1;}
Pagechangingeventargs ARGs =   New Pagechangingeventargs (INDEX );
Onpagechanging (ARGs );
}
}
If ( ! DesignMode)
{
Inputpageindex = Page. Request. Form [uniqueid +   " _ INPUT " ];
Int . Tryparse (inputpageindex, Out I );
If (I <   1   | I >   This . Pagecount)
{I= 1;}
Inputpageindex = I. tostring ();

}
Base . Onload (E );
}

 

 

The above methods are inherent in controls, and all controls will experience thisLifecycleThis process is relatively stable, but its internal implementation is not fixed but variable. This is why we can write controls with different functions.

 

For convenience, post a class diagram of the builder mode first:

 

 

The programmer is equivalent toDirector,His intention determines how the custom control is implemented. For example, I want to create a custom faceted navigation control,ControlClass is equivalent to builder, which is responsible for guiding a specific producer class (concretebuilder) if the intent of ctor Ctor is completed. the specific producer is concretebuilder. It completes the creation process of the control according to the control class instructions.

 

Such a program is not standard in the builder mode. It skips the abstract builder role and the director class.

 

It seems that sometimes you don't want to use a pattern. The pattern should be a natural phenomenon, and the design pattern is used to solve the problem, it is not mandatory for us to use it (the strong twist is not sweet), otherwise it will bring maintenance difficulties to the original simple system due to excessive design.

 

The code of the paging control above shows that the content structure of the so-called builder mode is complicated and often contains many methods. However, the creation process is relatively stable as a whole, however, its internal members are unstable. Each control has the same lifecycle, from initialization to rendering to final destruction, but the implementation process is different.

 

In this case, the relatively complex creation process can be abstracted to separate the creation process from the implementation process to achieve the same creation process.

The purpose of different expressions.

 

Features of the Creator mode:

1:The internal structure of the final product is relatively complex.
2:The product creation process is stable.
3:The implementation process of the internal objects of product is changeable.
4:The product does not care about how the internal subsystem is implemented (only the results do not care about the process ).
5:The creation process and implementation of product are separated.

6:The same creation process can achieve different performance results.

 

Applicability:

There is no unique standard. If developers feel that their projects are suitable for the characteristics of the Creator model, you can try to use them. Otherwise, they will still be used less.

Summary:

The design pattern is not far away from us. In fact, it is around us. It depends on whether you want to pay attention to its existence. A programmer who is good at application oo will always have the opportunity to regard the design pattern as the best weapon to solve the problem.

 

Note:

Reference: http://terrylee.cnblogs.com/archive/2005/12/19/299878.html

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.