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