Preface
==============================================================================
This PHP design mode album from the blog (jymoz.com), now has no access, this series of articles I have been looking for a long time to find the complete, thanks to the author Jymoz's Hard Pay Oh!
This address:http://www.cnblogs.com/davidhhuan/p/4248188.html
==============================================================================
StarCraft If it is multiplayer, you will encounter a problem: How to reduce network latency and burden.
In order to ensure the consistency of data, we should transfer each player's changed data to the host to open the map to save, once any one player's client read the data, it must request data to the host.
Although most of the data is interactive, even if a player's population is like this, if an enemy's forces kill one of the players ' troops, it immediately affects the number of his population.
However, the crystal ore and gas mine is different, except the player's own construction operations and farmers collection, other players can not affect the data.
So we consider the client also put a data store, the player changes or read his resources, the first operation of the computer data, and then notify the host.
Proxy Mode Example:
For convenience, it is assumed that the client has obtained the PHP code on the host through a remote inclusion or other method, with the following code:
<?PHP//an excuse for common implementation of client and host operational data Interfaceidataprocess {//The method that gets the data, $ID represents the player's ID, $dataName the name of the data that is obtained Public functionGetData ($ID,$dataName); //The method of changing the data, $ID representing the player's ID, $dataName the name of the data to be changed, $dataValue the value of the changed data Public functionUpdateData ($ID,$dataName,$dataValue); } //classes for host operation Data classDataprocessImplementsidataprocess {//The method that gets the data, $ID represents the player's ID, $dataName the name of the data that is obtained Public functionGetData ($ID,$dataName) { //manipulating code like a database } //The method of changing the data, $ID representing the player's ID, $dataName the name of the data to be changed, $dataValue the value of the changed data Public functionUpdateData ($ID,$dataName,$dataValue) { //manipulating code like a database } } //the class in which the client operates data, that is, the proxy class classProxydataprocessImplementsidataprocess {//objects for host operations data Private $dataProcess; //constructor Function Public function__construct () {$this->dataprocess =Newdataprocess (); } //The method that gets the data, $ID represents the player's ID, $dataName the name of the data that is obtained Public functionGetData ($ID,$dataName) { //determine whether to request directly from the host Switch($dataName) { //If the query Crystal mine Case' Ore '://read from data saved directly from the client, detail code skipped Break; //If the query gas mine Case' Gas '://read from data saved directly from the client, detail code skipped Break; default:$this->dataprocess->getdata ($ID,$dataName); Break; } } //The method of changing the data, $ID representing the player's ID, $dataName the name of the data to be changed, $dataValue the value of the changed data Public functionUpdateData ($ID,$dataName,$dataValue) { //similar to the idea of reading, if it is a crystal ore or gas mine, write to the client's data store, and then tell the host to modify } } //Create a new object for the client to process the data $proxyDataProcess=Newproxydataprocess (); //If the player's own amount of gas residue is displayed $proxyDataProcess->getdata (3, ' gas ');?>
Usage Summary: the proxy mode can let the customer operate a proxy class, do some work to reduce the resource consumption, can also complete such as authorization verification work.
Implementation Summary: requires an interface to specify the actual and proxy operation classes must implement methods, such as the above idataprocess, but also the actual processing of the class, such as the above dataprocess, and let the customer use the agent operation class, Like the proxydataprocess above. In fact, the proxy mode can be used in a variety of ways, confined to space, only to reduce the load of data manipulation.
Related articles:
1. StarCraft PHP Object-oriented (i)
2. StarCraft PHP Object-oriented (ii)
3. StarCraft PHP design mode-Simple Factory mode
4. StarCraft PHP Design mode-factory method mode
5. StarCraft PHP design mode-Abstract Factory mode
6. StarCraft PHP design mode-builder mode
7. The PHP design mode of StarCraft--The mediator mode
8. StarCraft PHP design mode--Enjoy meta mode
9. StarCraft PHP Design mode--proxy mode
10. StarCraft PHP design mode-prototype mode
11. The PHP design mode of StarCraft--Memo mode
12. StarCraft PHP design mode-template mode
13. StarCraft PHP design mode-positive mode
14. StarCraft PHP design mode-state mode
15. StarCraft PHP design mode--strategy mode
16. StarCraft PHP Design mode--combination mode
17. StarCraft PHP Design mode--responsibility chain mode
18. StarCraft PHP design mode-Observer mode
19. The PHP design mode of StarCraft--iterator mode
? 20. StarCraft PHP design mode-Adapter mode
9. StarCraft PHP Design mode--proxy mode