In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains "what is the web factory method". The content of the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "what is the web factory method".
motivation
The framework uses abstract classes to define and maintain relationships between objects. The creation of these objects is usually also the responsibility of the framework.
Object-oriented programming is actually programming abstract classes in many cases. We can think that the collaboration between abstract classes and abstract classes constitutes the architecture. In such an architecture, the creation part of the object is usually included.
Consider an application framework that can display multiple documents to the user. The two main abstractions in this framework are classes Application and Document. Both classes are abstract, and customers must implement specific applications through their subclasses. For example, to create a drawing application, we define classes DrawingApplication and DrawingDocument. The Application class is responsible for managing Document and creating them as needed-for example, when the user selects Open or New from the menu.
For this example, refer to Office. The specific operations of Excel and Word are very different, but from an abstract point of view, both Word and Excel can be regarded as Application, while Word documents and Excel documents can be abstracted as Document. With this view, file opening, closing, saving, content copying, pasting and other operations constitute Microsoft's application development architecture. Once you have this architecture, you can use it to develop your own applications, such as drawing software. This is because a large number of common parts have been completed, developers can quickly develop their own applications as long as they provide the corresponding concrete classes according to the specific needs.
When a user chooses to open or create a file through the application menu, the schema (actually Application) has an obligation to create the corresponding object.
Because the specific document subclass that is instantiated is application-specific, it is impossible for the Application class to predict which Document subclass will be instantiated-the Application class only knows when a new document should be created, not which Document will be created. This creates an awkward situation: the framework must instantiate classes, but it only knows abstract classes that cannot be instantiated.
Because the schema code is built before the application, it is impossible for an abstract Application to know the type of a representational Document class. That is, the architecture needs to instantiate certain classes, but does not know the types that actually need to be instantiated.
The Factory Method mode provides a solution for handling cases. It encapsulates the information about which Document subclass will be created and separates that information from the framework, as shown on the next page.
To solve this problem, the factory method pattern provides a way to separate parts that create concrete Document classes from the schema.
The subclass of Application redefines the abstract operation CreateDocument of Application to return the appropriate Document subclass object. Once an Application subclass is instantiated, it can instantiate documents related to the application without knowing the classes of those documents. We call CreateDocument a factory method (factorymethod) because it is responsible for "producing" an object.
First, the CreateDocument operation that returns the abstract Document is defined in the abstract Application class and used in the schema. When developing a specific application, implement a concrete Acpplication class that builds a figurative Document and introduce it into the architecture. This method of creating an object is the factory method.
Thank you for your reading, the above is the content of "what is the web factory method", after the study of this article, I believe you have a deeper understanding of what the web factory method is, 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: 239
*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.