an algorithm. For example, you might define algorithms that reflect different spatial/temporal tradeoffs. When these variants are implemented as a class hierarchy of an algorithm, the policy mode can be used.3) • The algorithm uses data that the customer should not know about. You can use the policy mode to avoid exposing complex, algorithmic-related data structures.4) • A class defines a variety of behaviors, and these behaviors appear as multiple conditional statements in the operation of thi
Recently read "Simple design mode" This book, a lot of harvest, is going to write a series of blog, and Python to achieve each of the design patterns to deepen understanding.
Here is the first design pattern in the book: strategy mode
In the book to simulate the application of ducks as an example, a game application re
) {//Select and create the policy object you want to useDiscountstrategy Discountstrategy =NewIsmemberdiscountstrategy (); //Create an environmentCalculatedprice Calculatedprice =NewCalculatedprice (discountstrategy); //Calculate PriceCalculatedprice.quote (300); }}Advantages of the policy model(1) The Strategy mode provides a way to manage the associated algorithm families. The hierarchy structure of a policy class defines an algorithm or a family of
Design strategy of online survey tableThe questionnaires are ubiquitous on the Internet, especially by survey companies, who request that everyone browsing their site participate in their various surveys.
But in fact, many of the online questionnaires are poorly designed, sometimes taking too much time, confusion, or even boredom from the respondents, and the data collected by a poorly designed questionna
is not unique, there are numbers, and there are phone numbers. Thus they may have a requirement for the verification of each individual.The policy pattern is reusable, for example, multiple fields may require validation non-null, and we can abstract the scenario's validation policy into a set of policiesWhen the user needs to validate the form data, only the incoming data and the validation policies of each field are required, the corresponding validation results can be given, thus separating t
Separating the invariant parts from the changed parts is the subject of each design pattern.
All roads lead to Rome. We often get to solve one thing. There are a variety of scenarios, such as compressed files, we can use the zip algorithm, you can also use the GZIP algorithm. Its flexibility and diversity, we can use the strategy model to solve.
I. Definition
Define a series of algorithms that
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.