Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the implementation of the BUILDER pattern?

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

The main content of this article is to explain "what is the implementation of BUILDER pattern". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Next, let the editor take you to learn "what is the implementation of the BUILDER pattern?"

Effect.

It separates the construction code from the presentation code

The Builder pattern separates the code that builds the object from the code that represents the object. The construction here is biased towards the abstract indicative part, while the representation (expression) is biased towards the actual output. For example, when we say installing a door, for the building model, it may be gluing a small plank to the model; for the workers on the spot, it may really be installing an anti-theft door. The installation of a door here is an abstract indication, while gluing a small plank or installing an anti-theft door is part of the concrete expression.

The Builder pattern improves the modularity of objects by encapsulating the creation and representation of a complex object. The customer does not need to know all the information about the classes that define the internal structure of the product; these classes do not appear in the Builder interface.

Generally speaking, the construction of any object has a process from abstract construction to concrete construction (implementation, expression). After separating the two processes, there is no need to understand the way and content of the interface implementation on one side of the interface, so the object is more modular.

Of course, this separation will have practical significance only when it is complex to a certain extent. Whether to separate or not, the designer needs to judge according to his own point of view.

Each ConcreteBuilder contains all the code to create and assemble a particular product. This code only needs to be written once; then different Director can reuse it to construct different Product based on the same set of parts. In the previous RTF example, we can define a reader for a format other than the RTF format, such as a SGMLReader, and use the same TextConverter to generate ASCIIText, TeXText, and TextWidget translations of the SGML document.

Specifically, the Builder class takes on the part of the actual build, which should contain the code that generates the specific product. For each category (not each) product, this part of the code needs to be written only once; the logic of the abstract build can be determined by different Director or different logic of the same Director.

First, take a look at the class diagram of the instance in Design pattern:

Interfaces for converting characters, fonts and paragraphs are defined in TextConverter.

DocumentBuilder defines the interface for the document to start, end, and generate Title1,Title2,Text.

This kind of difference is actually a question of how to define the Builder interface in the actual development. On this issue, the author's point of view is:

Interfaces should be defined from the point of view of the Director world.

The definition of the interface should also take into account the realizability of representations like Builder.

At this point, I believe you have a deeper understanding of "what is the implementation of the BUILDER pattern?" you might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report