Design Pattern-Builder pattern and design pattern builder

Source: Internet
Author: User

Design Pattern-Builder pattern and design pattern builder

Separates a complex build from its representation so that different representations can be created during the same build process.

-- Design Pattern GOF



In the ASP. NET environment, Insus. NET lists a Builder design pattern (Builder) example, which is closest to the development environment and requirements.

When developing websites, we need to develop news, videos, and images. Each webpage may also contain the page header, content, and footer. When developing these page headers, content and footer, we use user controls to write and load them to webpages.

For webpages of each category, you create three new user controls (ascx), NewsHeader, NewsContent, NewsFooter, xxxHeader, xxxContent, xxxFooter, and so on ......

NewsHeader. ascx:


NewsContent. ascx:


NewsFooter. ascx:



That is to say, to refine and maintain each page into a user control.

Now we need to build a webpage (product) which consists of three parts.


There will be many web pages that show articles, news, videos, and images as listed above. We need to define an abstract common interface so that a specific class has a unified standard:


The builder's design model also has a role, namely the conductor:


Now we can build specific classes, real products (webpages), newpages, VideoPage, and ArticlePage:



Now, we need to display the complete product (webpage) on the actual webpage ):
In xxx. aspx, pull a control container, such as PlaceHolder. Here we only show the list. In the actual environment, you may need to pull several containers to define and dynamically load them on the webpage.


Xxx. aspx. cs:


When the webpage is running, check the effect:

 

The following content is added:
Forgot to share the complete DEMO code: http://download.cnblogs.com/insus/CSharpNET/DesignPattern_Builder.rar

 

Related Article

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.