page independently, and take the form of static pages, which is helpful for spiders to crawl and page load.2, set the site SEO titleFilter the appropriate long tail keywords, set the SEO title for the site page, rather than show it in the search results: About us, it doesn't make sense for search optimization.It is noteworthy that the H1 title of the content page and the logical structure of the entire paragraph.3, including: Sitemap, highlighting the core product listOn the Site page, you need
(strategy) mode: There is often a problem in the business there is a set of algorithms, in different cases we may use different algorithms.We need to find a flexible and easy way to design: encapsulate each algorithm in a separate class with a common interface, so that they can be replaced with each other. 2 structure diagram: 3 For example: a common shopping problem: To quote to the customer, for the sale
helicopter ride. Each policy can get the same result, but they use different resources. The choice of strategy is based on cost, time, use of tools, and the convenience of each of these methods. A good strategy may not be used again the next day, so the choice of strategy is relative.
You have seen a similar example of a st
0. Suppose an existing project (Duck) encounters an issue that adds functionality to a class, how do I design a class to add new functionality?1. What are the disadvantages of using the duck (duck) provided by inheritance?
(1) Code repeats in multiple subclasses
(2) Many men know the whole behavior of all ducks
(3) The behavior of the operation is not easy to change
(4) Change will lead to the whole body, causing the other ducks d
behavior, it doesn't affect the behavior of the original object.
SummarizeThe policy pattern applies to scenarios where there are many similar objects that have similar behavior and that the behavior is constantly changing. The policy pattern encapsulates the algorithm so that the algorithms can be replaced with each other, and this substitution is independent of the client using the algorithm.The strategy model embodies the principle of softwar
Operate () { System.out.println ("Mrs. Sun , blocking the pursuers ");} }Environment Class (Context)public class Context { private strategy strategy; constructor, which trick you want to use public Context (strategy strategy) { this.strategy = str
print (String info) { SYSTEM.OUT.PRINTLN (info);} }Package Com.pattern.strategy;import Com.pattern.strategy.role.king;import Com.pattern.strategy.role.queen;import Com.pattern.strategy.role.role;import Com.pattern.strategy.weapon.axebehavior;import Com.pattern.strategy.weapon.knifebehavior;import Com.pattern.strategy.weapon.swordbehavior;public Class Strategymode {public static void Main (string[] args) { role role = new King (); Role.setweaponbehavior (New Axebehavio
abstract class; unchanging contentFlywithwings implementationFlybehavior interface, variable content, behavior, or algorithmThe setter method is provided in Duck.java to assemble the relationship;Dynamic setting behaviorThe above is the implementation of the strategy model three-step. Next, let's look at the essence through the steps:1)Initially, we use inheritance to implement behavior reuse, resulting in code maintenance issues. Inheritance, is a2)
strategy mode can use this formula: different XXX has different xxx for the user to choose. For example, different chess pieces have different ways for the user to choose. Here are some simple examples of different weapons for users to choose from, depending on the characters in the game:first, UML model diagramSecond, the code implementation/** * Weapon-template */interface weaponbehavior {void Useweapon ();} Class Knifebehavior implements Weaponbeh
Intent: Define a series of algorithms, encapsulate them one by one, and make them interchangeable with each other. The policy pattern allows the algorithm to change independently of the customers who use it.1. Need to use the algorithm provided by Concretestrategy (specific policy role);2. Maintain an instance of strategy (abstract policy Class) internally;3. Responsible for the dynamic setting of the runtime stra
Policy Modepolicy mode : Refers to a specified object has a behavior, but in different scenarios, the behavior has a different implementation way. by implementing the different implementations independently, and allowing them to be replaced by each other , so that the different ways independent, for the user to choose.UmlThe following is a simple arithmetic operation using the policy pattern: package strategy; /** @author WxH * @vertion 1.0 *
uses a simpler, incoming parameter (the activity type, the original price) to get the final result.Here the user only needs to know a class (Cashcontext) can be, and simple workshop need to know two classes (Cashfactory Accept_cash method and Cashfactory), that is more thorough encapsulation.Advantages of the policy modelThe algorithms are encapsulated in 1,cashcontext, and these algorithms are all doing the same work, just implementing different, which helps to extract the common functions in
In my design Journey: Strategy pattern (primary) (C + +) (OO C + +) (Template C + +), we used strategy pattern to let graph Er can draw triangle, circle and square
Because the need to change again,:D, we hope that Grapher will be able to print the text in each shape, the implementation of the results are as follows
Draw Hello Shape!! in Square Draw Hello C++!
Setflybehavoir (Flybehavior fb) {mflybehavior = fb;} public void Swim () {System.out.println ("~~im swim~~");}} See no, abstract superclass does not have any specific implementation class coupling, but is called through the interface. Inside the fly or quack function, are based on the same kind of mflybehavior and mquackbehavior different. Take a look at the green-headed duck and the red-headed duck implementation process. public class Greenheadduck extends Duck {public Greenheadduck () {mflybe
Division: Divide and Conquer, also known as Divide and conquer, is a very useful algorithm design strategy, it is a difficult to solve the large problem scale into some small sub-problems, solve each sub-problem, and then merge the solution of the sub-problem. As a matter of course, there are three steps to design a divide-and-conquer approach:(1) Divide division
Strategy | design
Although find Shan Tianfang to broadcast the weather forecast is only a sketch in the bridge section, but, if really to say storytelling way, the "weather forecast", "world events" as a story, said "Arabian Nights." The boring news and reports are bound to have higher ratings. "Tell the story", is not a gimmick, but from the ancient Shino, the Ming and Qing dynasties, to Shadow, Peking Ope
();
}
advantages of the policy model:
The algorithm is free to switch
This is defined by the policy pattern itself, and as long as the abstract policy is implemented, it becomes a member of the policy family and encapsulates it by encapsulating the role, guaranteeing a "free handoff" strategy.
Avoid using multiple conditional judgments
If there is no policy model, let's think about what it would look like. A policy family has 5 policy al
When you do one thing to complete a task, there are often many methods, each of which can be called a policy, we will according to different environments or conditions, select an appropriate method from multiple methods to complete this task or task. Just like when we go home, there are many ways to go home, such as taking a plane, taking a train, taking a bus, and walking. However, due to our own restrictions or environmental restrictions, we often choose a suitable way to go home. The method w
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.