In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains "what are the advantages of prototype". The content of the explanation is simple and clear, and it is easy to learn and understand. Please follow the editor's ideas to study and learn "what are the advantages of prototype"?
Effect.
There are many Prototype and Abstract Factory (3. 1) and Builder (3. 2) the same effect: it hides specific product categories from customers, thus reducing the number of names that customers know. In addition, these patterns enable customers to use classes related to a particular application without change.
Hiding elephant classes, programming against abstract classes is not so much the generality of creating object patterns as the commonness of most design patterns. Furthermore, it should be said that it is the commonness of object-oriented programming technology. The important thing is said three times, and it cannot be overemphasized in the face of abstract class programming.
Some other advantages of the Prototype mode are listed below.
The following advantages are unique to the prototype pattern.
1) add and delete products at run time
Prototype allows a new specific product class to be incorporated into the system simply by registering a prototype instance by the customer. It is more flexible than other creative models because customers can build and delete prototypes at run time.
This is the most useful scenario for prototype patterns. Generally speaking, architecture is responsible for defining the way all kinds of data and objects interact with each other. After the architecture development is complete, we certainly hope that it can be applied to future data and objects without change. Adding and removing products at runtime makes it possible to achieve this wish.
It is important to note that the product here is not the output of the program, but the objects that the application needs to use and deal with.
2) change the value to specify a new object
A highly dynamic system allows you to define new behavior through object composition-for example, by specifying a value for an object variable-without defining a new class. You can effectively define new categories of objects by instantiating existing classes and registering these instances as prototypes of customer objects. Customers can delegate responsibilities to the prototype to show new behavior.
The so-called highly dynamic system means that users are free to define the behavior of the program. For this behavior of modifying the definition, the basic method is to modify the parameters, and the advanced method is to use the combination of existing objects. Either way, the action mode of the system is to take the defined object as the prototype and clone the prototype to get a new instance to be used in the system.
This design allows users to define new "classes" without programming. In fact, cloning a prototype is similar to instantiating a class. The Prototype mode can greatly reduce the number of classes required by the system. In our music editor, a GraphicTool class can create countless kinds of music objects.
Although this design does not get a new class programmatically, it is not fundamentally different for the user from the effect of building a new class and generating objects. Because the new classes are not really built, the number of classes required by the system is reduced.
3) change the structure to specify a new object
Many applications use assemblies and subassemblies to create objects. For example, the circuit design editor is constructed by sub-circuits. For convenience, such applications usually allow you to instantiate complex, user-defined structures, for example, to reuse a specific subcircuit over and over again.
The Prototype mode also supports this. We only need to add this subcircuit as a prototype to the available circuit element selector. As long as the composite circuit object implements the Clone as a deep copy (deep copy), circuits with different structures can be prototypes.
The DOS version of Protel has custom features for components: you can build your own library and use it by defining the shape of the component, pins and other simple operations. After learning the design pattern, we know that those functions can be realized through the prototype pattern.
It doesn't matter if you haven't used the circuit board design software. The library, template and other functions in Office that can be loaded separately can be realized by using prototype pattern.
4) reduce the construction of subclasses
Factory Method (3. 3) often produce a Creator class level parallel to the product class level. The Prototype pattern allows you to clone a prototype instead of requesting a factory method to produce a new object. So you don't need the Creator class hierarchy at all. This advantage mainly applies to languages like C++ that do not treat classes as first-level class objects. Languages like Smalltalk and Objective C benefit less because you can always use a class object as a generator. In these languages, class objects have played the same role as prototypes.
Regardless of the way or language, the process of creating an object is always needed. Which mode to choose is generally considered by considering the requirements of code expansibility, independence and simplicity. The advantage of choosing the prototype pattern is that you no longer need a parallel Creator class hierarchy, but the downside is that the code for building the object and the code for the object itself are contained in the same class. Which mode is adopted will test the designer's ability to apply the design pattern according to the actual situation.
Thank you for your reading, the above is the content of "what are the advantages of prototype". After the study of this article, I believe you have a deeper understanding of what the advantages of prototype are, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.