In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-21 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
Today, the editor will share with you the relevant knowledge about the structure of the web visitor pattern. The content is detailed and the logic is clear. I believe most people still know too much about this, so share this article for your reference. I hope you can get something after reading this article. Let's take a look at it.
structure
The idea encapsulated in object-oriented is to centralize data and methods of manipulating data in one class to achieve the effect of high cohesion and low coupling. But sometimes you want to centralize purpose-related or identical operations for different types into one class. This approach is the Visitor pattern, which is structured as follows:
The visitor class Visitor defines two derived classes with two different interfaces for accessing the two Element in the lower half of the construction diagram. The visitor class Visitor determines the types of objects that its derived classes can access in different ways.
The concrete visitor class ConcreteVisitor class is responsible for implementing specific operations for a set of objects specified by the visitor class. Each access method is often part of a larger algorithm, so it is often necessary to use data members of a concrete visitor class to save information about this algorithm. Due to different requirements, it is not required that every concrete class must implement all access methods.
The element class Element, as the base class of the feature class, should first have its own function, and then define the accpet method used to accept the visitor class for the representational feature class on the inheritance level. You can also define an abstract class with only accept methods, but personally it feels like putting the cart before the horse. The class structure of the feature class should still be designed according to its own requirements, rather than being changed for the convenience of the visitor pattern at the implementation level.
As the visiting object of the visitor, the concrete feature class ConcreteElement is responsible for entertaining the visitor. The corresponding method of Visitor is called in its accept method. This process can be seen as automatic matching between the access object and the access method of the Visitor after putting the concrete Visitor class and the access object together. This can also be thought of as a kind of overloading, which is the most magical part of the visitor pattern.
The object structure ObjectStructure is just a formulation, and there is no such class. The reason why this role is needed, I think it can be understood like this: the processing of a data structure can always be seen as a combination of data structure traversal and data processing. The Visitor class is only responsible for processing, so you need a role to advance the traversal action, and that role is ObjectStructrue. Since Visitor is always in a passive position throughout the process of traversal and processing, it doesn't care what the structure of ObjectStructure is. And this doesn't care is the decoupling in object-oriented.
These are all the contents of the article "what is the structure of the web Visitor pattern?" Thank you for reading! I believe you will gain a lot after reading this article. The editor will update different knowledge for you every day. If you want to learn more knowledge, please pay attention to the industry information channel.
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.