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 structure of web policy pattern?

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

Share

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

Most people do not understand the knowledge points of this "web strategy pattern structure" article, so the editor summarizes the following content, detailed content, clear steps, and has a certain reference value. I hope you can get something after reading this article. Let's take a look at this "web strategy pattern structure" article.

Intention

Define common interfaces for a series of algorithms so that they can be replaced with each other.

motivation

Suppose we have a data processing software that needs to do some processing after it gets the data. These processes can be simple, such as limiting, finding absolute values, etc., or they may be more complex, such as moving averages, calculating differences, and so on. Generally speaking, it will not be too difficult to consider these processes separately. But the trouble is that different forms of processing may be required depending on the data and requirements. What is more troublesome is that the specific type of input data, the requirements can not be determined until the software is executed, that is, these processes need to be replaced dynamically.

To solve this problem, we can define common interfaces to abstract these processes. For the above example, defining a yallowf (x) should satisfy the requirement. For any output, just produce the appropriate output. For processing such as moving averages, it may be a little more troublesome, but it can be solved by preparing an internal buffer to manage data from the past.

structure

When some processes can abstract the same interface, but the internal specific behavior is different, you can use the policy pattern to achieve the purpose of dynamically changing the content.

The policy class Strategy defines a processing interface for common use. Context uses this interface to invoke the appropriate processing. The processing here can be the processing of the data, or it can just perform an action.

The concrete policy class ConcreteStrategy is responsible for implementing the interfaces defined by the policy class. As long as the consistency of the interface is ensured, the concrete policy class is free to extend new functions. In order to achieve this, the concrete policy class often needs to maintain some necessary information. This is also a convenience after encapsulating the policy into classes.

The context class Context class first needs to manage a reference to a policy class object. Depending on the user's specification or otherwise, this reference can point to any specific concrete policy class ConcreteStrategy. However, when the data processing process is executed, the context class is also responsible for providing input data and fetching output data for the policy object. The context that determines the policy, the context of managing and using the policy is not necessarily the same object.

The above is the content of this article on "what is the structure of web strategy model". I believe we all have a certain understanding. I hope the content shared by the editor will be helpful to you. If you want to know more about the relevant knowledge, please follow 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.

Share To

Internet Technology

Wechat

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

12
Report