A Preliminary Study on Android development strategies and android strategies

Source: Internet
Author: User

A Preliminary Study on Android development strategies and android strategies
The rule mode mainly defines a series of algorithms. Those who have learned the data structure know that there are many algorithms for sorting arrays from large to small, such as bubble, exchange, and fast insertion, policy mode encapsulates these algorithms into independent classes for convenient calls. Here we take string substitution as an example. There is a file. After we need to read it, we want to replace the corresponding variable and then output it. there may be many ways to replace the variables, depending on the user's requirements, so we need to prepare several sets of variable character substitution solutions.

First, we create an abstract class RepTempRule to define some public variables and methods:

public abstract class RepTempRule{ protected String oldString";  protected String newString; public void setOldString(String oldString){this.oldString=oldString; }public String getNewString(){ return newString; }public abstract void replace() throws Exception; }

There is an abstract method in RepTempRule that needs to be clearly inherited. In this replace, it is actually a specific alternative method. Next we will inherit this abstract class to implement its specific replacement algorithm. Assume that there are two character substitution schemes: 1. Replace aaa with bbb in the text; 2. Replace aaa with ccc in the text; the corresponding classes are RepTempRuleOne RepTempRuleTwo

Public class RepTempRuleOne extends RepTempRule {public void replace () throws Exception {newString = oldString. replaceFirst ("aaa", "bbbb") // replaceFirst is the jdk method System. out. println ("this is replace one ");}}

Step 2: Create an algorithm solution class to provide clients with the freedom to select algorithms.

Public class RepTempRuleSolve {private RepTempRule strategy; public RepTempRuleSolve (RepTempRule rule) {// constructor this. strategy = rule;} public String getNewContext (Site site Site, String oldString) {return strategy. replace (site, oldString);} // public void changeAlgorithm (RepTempRule newAlgorithm) {strategy = newAlgorithm ;}}

Step 3: Execute the algorithm

RepTempRuleSolve solver = new RepTempRuleSolve (new RepTempRuleSimple (); solver. getNewContext (site, context); // use the second set of solver = new RepTempRuleSolve (new RepTempRuleTwo (); solver. getNewContext (site, context );

In reality, the core part of Strategy is the use of abstract classes. The Strategy mode can be used with a small amount of modifications and fast modification when users need to change.
There are some similarities between Strategy and Factory. Strategy is relatively simple and easy to understand, and can switch freely at runtime. Factory focuses on creating objects.
Strategy is applicable to the following scenarios:
1. save files in different formats;
2. Use different algorithms to compress files;
3. capture images using different algorithms;
4. output images of the same data in different formats, such as curves or Block bar



For Android strategy games, we recommend several

Kill Three Kingdoms
Royal Guard

Little empire

Death squads
This is war

Glory of generals

I personally think these strategy games are quite good. You can try them.

Android mobile strategy games

You are talking about anti-tower games.
We recommend two types of defense I have played: Magic tower defense (non-cheating version) Plants vs. botnets (Android perfect version)
There are various game introductions and recommendations in various major Android forums. I haven't played many games. You can search for them yourself.

Related Article

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.