The intent of the policy pattern is to encapsulate each algorithm in a separate class with a common interface for a set of algorithms, so that they can be replaced with each other. The policy pattern allows the algorithm to change without affecting the client.The strategy pattern is the wrapper over the algorithm, which divides the responsibility of the algorithm and the algorithm itself, delegating it to different object management. The
The policy pattern is a simple basic pattern used to encapsulate a series of algorithms that make client Access independent of the algorithm's implementation. We can describe the strategy pattern by "taking water in the well". "Take the Water" is an action, the way to complete the action there are many, you can directly with the hand, can use water tankers, can also be pumped water pump. Under different circumstances and conditions, we choose differen
Document directory
Implementation problems in the base class
Override the problem of Basic Methods
PDF download: http://www.tracefact.net/Document/Strategy.pdf
Introduction to fantasy RPG (role skills and Strategy Mode)
I have read some books and articles on design patterns. Although they are formal and authoritative (and I think there are some stereotypes), they always feel that people are not so close. As a result, I think about writing my own u
Scenario Description:
When I woke up, it would take 30 minutes to get to work. I decided to wear my clothes, smoke a cigarette, brush my teeth, and wash my face. I went to work slowly; if I woke up for 15 minutes, I would be late. Even if I had forgotten to smoke, I would like to wear my clothes, brush my teeth and wash my face, and rush to work. If I woke up for only five minutes, I would be swollen! It took 5 seconds to restore your mood and quickly got dressed and rushed out!
We can find that
Policy mode (strategy): It defines the algorithm family, respectively encapsulated, so that they can replace each other, this mode allows the algorithm changes, will not affect the use of the algorithm users.You should consider using the policy mode in the following scenarios:1. If there are many classes in a system, the difference between them is only their behavior, then the use of a policy model can dynamically let an object in many behaviors to ch
Article Description: 4 factors that affect the user experience.
With the development of Internet products, more and more people are aware of the importance of user experience, more and more companies set up ued related departments, and the Division of jobs has been very meticulous. But the division of functions in the ued, but most of the docking interface only level. In fact, an Internet product from the production of a strategy to the fin
Article Description: Let's say these 4 factors separately. Each of these factors is illustrated with 2 examples of this factor, one on the Internet, and the other on a similar example in everyday life. All the cases involved, just at the level I can see (which means that the problem I'm describing may be reasonable or problematic at the level I don't see),
With the development of Internet products, more and more people are aware of the importance of user experience, more and more compa
Temperature so know new, each reading design mode will have a different experience, adhere to a design pattern every day, until skilled use of design patterns.The policy pattern defines many algorithms that do the same work, but with different implementations, it can invoke all the algorithms in the same way, reducing the coupling between the algorithm and the calling algorithm.The following is the strategy class diagram of the big talk design pattern
The example of this article for everyone to share the Java strategy model for your reference, the specific contents are as follows
1, the Strategic model (strategy pattern) is a relatively simple model, also known as the Policy Model (Policypattern).The definition is as follows:
Define a family of algorithms,encapsulate each one,and make them interchangeable.(defines a set of algorithms that encapsulate e
Internet | microsoft | Strategy NET: Interpreting the new Microsoft Internet Strategy (on) (Seal Dragon Pavilion Collection, strongly recommended!) )
http://www.chinabyte.com/column/column_page.shtm?column_type=comp_searchcoluid=2215
"Author" Mao Xianhui Chen Zhihong
Article outline:
First, the big strategic shift
1,. NET is what?
2,. NET is the transformation of computing mode
3,. NET's transformation
Whatever you do, set a goal, have a core strategy for a goal, and resolutely implement the core strategy is the Magic weapon for success.
Give me a chestnut:
The Three Kingdoms are divided into the world. Wei have their own phased core strategy. Wei Cao's strategy is to take the emperor to make princes. Dong Wu Sun Qua
Policy patterns define a series of algorithms, encapsulate each algorithm, and make them replaceable. The rule mode allows algorithms to change independently of customers who use it. (Original article: The Strategy Pattern defines a family of algorithms, encapsulates each one, and makes them interchangeable. Strategy lets the algorithm vary independently from clients that use it .)
Context ):
1. The Concret
is its variability, consistency, and transmission in contact with human populations. These abstract features are precisely the efficient quality of the Internet users. The process of multiple network events reflects these key models. The natural process of these time periods is that, first, some personal posts or information are posted to form a certain inflammatory pattern, and then the Internet is magnified due to the spread of the Internet, after debate and filtering, the netizens gradually
In-depth understanding of JavaScript series (19): Evaluation strategy
This article mainly introduces how to thoroughly understand the JavaScript series (19): Evaluation strategy (Evaluation strategy, this article describes general theories, passing by value, transferring by reference, calling by sharing, and passing by share are special cases of passing by value,
In Gof's design model: The basics of reusable object-oriented software, the strategy pattern is said: Define a series of algorithms, encapsulate them one by one, and make them interchangeable with each other. This pattern allows the algorithm to be independent of the customers who use it.Strategy mode in order to adapt to different needs, only the change point encapsulation, the change point is to achieve different requirements of the algorithm, but u
In most cases, template method and strategy can complete the same task, that is, to complete the task in a certain step without relying on the implementation of specific steps. The implementation of the specific step of template method downgrading is left to the subclass, while Strategy leaves the specific implementation to any class that follows a specific interface. The vast majority of frameworks can fin
. Here's the explanation: for example, when the order order = Customer.iterator (). Next () iteration returns the proxy instance of orders. The order was not instantiated at this time, so no SQL query was made. It is instantiated only when it is called on its properties or methods, such as when the order number: Order.getorderno () is obtained.Lazy There are other options extra enhancements, such as the Size/contains of a collection of orders, and so on, will not initialize the orders, but the d
narrow interface?Source code download:VirtualMethod.rar(VS2005 console Project)
2nd designs: narrow Interfaces
As shown in, a concept is extracted in this design: Flyable.
Please note how important it is to explicitly present a concept: now we all know which functions should be implemented to be "Flying" and know that Mallard Duck and Redhead Duck will fly, rubber Duck does not fly.But this design also has a major drawback: Mallard Duck and Redhead Duck Fly () are repetitive code, but we cannot
runtime" function was only available in Strategy. Although the operating principles behind it are different, this design can still give a feeling that the behavior of the duck. Quack () method is "dynamic.
Can it be used as a substitute for Strategy? No, never. The semantics shown by Strategy is that "Mallard Duck has a way to tweet-screamOr"(The example of
parts of the algorithm. By introducing the strategy pattern, the algorithm is encapsulated so that it can be flexibly extended and replaced.
Sample code
using System; using System.Collections.Generic; using System.Text; using System.Collections; namespace Strategyexample { Class Program { static void Main (string[] args) { Data data = new data (); data. ADD ("AAA"); data. ADD ("BBB"); data. ADD ("CCC"); data.
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.