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.