Class strategy
...{
Public:
Virtual void output (string S) = 0;
};
Class showstrategy: public strategy
...{
Public:
Virtual void output (string S)
...{
// The output string is used for simulation, but it may be a function like MessageBox in the actual project.
Cout }
};
Class logstrategy: public strategy
...{
Public:
Virtual void output (string S)
...{
// Here
As a PHP developer, know that many programmers have despised PHP, why? Because they think PHP syntax is dirty, and because of the uneven level of developers, PHP code is more chaotic, maintenance is almost a lump of shit. As PHP joined the object-oriented formation, many developers began to use OOP ideas to write code, and PHP became more and more standard and more standardized. And the design pattern plays a very important role. Recently, the boss to
() { echo"2014新款女装"; } function showCategory() { echo"服装"; 5.3 Defining strategies for male usersclass MaleUserStrategy implements UserStrategy { function showAd() { echo"IPhone6"; } function showCategory() { echo"电子产品"; 6. Page display and use class Page{ //Save policy Object protected $strategy;//Home Information output function index(){ //traditional notation, with outpu
add a user, you need to rewrite the code. Using the policy mode, if you add a new user type, you only need to add one more policy. All other places just need to use a different strategy.The interface file for the policy is declared first, and the contained behavior of the policy is contracted. Then, define each specific policy implementation class.Example:PHP//declares the interface of the policy file, and the behavior that the contract policy contains. Interfaceuserstrategy{ Public functionSho
Strategy Mode of design patternLearning:http://blog.csdn.net/hguisu/article/details/7558249/1. What is a policy model?In software development also often encounter similar situation, to achieve a certain function has a number of algorithms or strategies, we can choose different algorithms or strategies according to the environment or conditions to complete the function . the
care. The context selects specific policy algorithms. This will be demonstrated later when we talk about fault tolerance recovery.
(5) implementation of strategyIn the previous example, strategy is defined by interfaces, which is also a common implementation method. However, if multiple algorithms have public functions, You can implement strategy as an abstract class, and then implement the public functi
First, prefaceLearn the first design pattern! Do not know the right to understand, I expect you to communicate more ~Strategy mode: The strategy mode, defines the algorithm family, separately encapsulates, this pattern can make the algorithm's change independent to use the algorithm the customer. The strategy mode enca
web| Strategy | design | Site believe that a large number of people know that many of our domestic web site design projects have a feature, that is the design and production confused. The so-called design site, is simply the customer to the data graphics, regardless of any o
= Adapterview.item_view_type_ignore; int getitemviewtype (int position); int Getviewtypecount (); static final int no_selection = Integer.min_value; Boolean isEmpty ();}And then to the abstraction of BaseadapterPublic abstract class Baseadapter implements ListAdapter, Spinneradapter { private final datasetobservable mdatasetobservable = new datasetobservable (); public Boolean hasstableids () { return false; } /** * Notifies the attached observers that the under
Badquack implements quackbehavior{public void Quack () {System.out.print ("cant ' t quack");}}Test:public class Greenduck extends Duck{public Greenduck () {flybehavior = new flywithwings (); quackbehavior = new Quack ();} public void display () {System.out.print ("real Duck");}} public class Test {public static void main (String []args) {Duck Greenduck = new Greenduck (); Greenduck.performfly (); Greendu Ck.performquack (); Greenduck.setflybehavior (new Flynoway ());//dynamic change of the beha
specific strategy ( algorithm ) Implementation details, each other completely independent ;3, the Strategy mode simplifies the unit test, each algorithm has its own class, can be tested by its own interface alone;4. the client must know all the policy classes and decide for themselves which policy class to use. This means that the client must understand the differences between these algorithms in order t
Design Mode-Strategy Mode
1. Solved problems: If you want to write a shooting game that contains different levels of game roles, these roles can use different weapons.
2. Problem Analysis: The role should be able to change weapons dynamically. In the future, other roles or other types of weapons may be added. according to the principle of "Separating variable parts and encapsulating them separately", wea
specific algorithm is implemented with strategy interface. A at3. Context - configured with a Concretestrategy object. - maintains a reference to the Strategy object. -You can define an interface to let stategy access its data.Test class:1 Public classTest {2 3 Public Static voidMain (string[] args) {4Context CTX =NewContext (NewStrategyimpla ());5 Ctx.domethod ();6 7CTX =NewContext (
different times of the system, the same system may be in different business modes, so it is necessary to analyze the business application at the peak of the system. The goal is to determine whether the peak business application model is a single business type or a hybrid business type by analyzing peak applications, which is critical to the design of the late test case execution strategy. For example, many
Recently, Baidu's policy updates have prompted the Internet to "focus on content construction". webmasters began to discuss how to build websites, what kind of website design can feed spider appetite? I have recently studied how to develop an amazing website to cater to Baidu's new strategy. Here I will share my thoughts with you.
First, friendly navigation settings. When building a website, you must consid
Recently found a good book "Your design Mode", after reading two chapters can assert, must be a need for the cock silk writing, and is specially written for development cock Silk Man's wisdom Pillow book, The Little Woman on the grievance, reluctantly see, people stupid, who let him write so easy to understand it! Write it down in your own way to deepen your understanding.The first chapter of the strategy m
communication algorithm{Ct. Setstrategy (NewLan ()); } Else{Ct. Setstrategy (NewSerial ()); } Ct. Send (data); Console.readkey (); } }}Operation Result:As can be seen from the above example, strategy is similar to Factory mode, but factory changes the object when it is created, and the strategy mode is free to switch.The strategy
combined, and the strategy is only a level of an algorithm in decoupling, not to the level of the system.As can be seen from the structure diagram, the structure of the policy mode is inclusive in the bridge mode structure, abstraction and implementor can be considered as the policy mode, but the bridge mode General Implementor will provide a series of system operations, And implementor is a static structure with state and data. And the bridging mode
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.