「Stratery Pattern defined algorithm family, were packaged together so that they can replace each other between, so that the algorithm change will not affect users using the algorithm.」
Features:
• Define and encapsulate a family of algorithms.
• Make encapsulated algorithms interchangeable.
• Allow algorithms to change independently from the clients that use it.
UML:

Example:
Build a [ Magic System ] interface,Name it:MagicSystem.as.
MagicSystem.as
package{ public interface MagicSystem { //use magic function magic(); //show magic name function showMagicName():String; } }
MagicSystem has magic() and showMagicName()
Here's three MagicSystem below...
FireBallBullet.as
package{ public class FireBallBullet implements MagicSystem{ public function magic() { trace("use Fire Ball"); } public function showMagicName():String { return "Fire Ball"; } } }
IceStormBullet.as
package{ public class IceStormBullet implements MagicSystem{ public function magic() { trace("use Ice Storm"); } public function showMagicName():String { return "Ice Storm"; } } }
LightningBullet.as
package{ public class LightningBullet implements MagicSystem{ public function magic() { trace("use Lightning"); } public function showMagicName():String { return "Lightning"; } } }
We implement MagicSystem interface and build three magic classes.
(Here's we only use trace() to represent different magic)
Than we build a new class,name it "Magician.as".
(It has MagicSystem)
Magician.as
package{ class Magician{ //MagicSystem private var magicSystem:MagicSystem; public function Magician() { //The default is FireBallBullet magicSystem= new FireBallBullet(); } //Use magic public function magic() { magicSystem.magic(); } //Change magic public function changeMagicSystem(ms:MagicSystem) { trace("Change magic ==> "+ms.showMagicName()); this.magicSystem = ms; } } }
Now we can test it.
Open a new file(GameScene.as),follow the code below...
GameScene.as
package{ import flash.display.Sprite; public class GameScene extends Sprite{ //creat a player private var player:Magician = new Magician(); public function GameScene() { //use default magic player.magic(); //output:use Fire Ball //change magic player.changeMagicSystem(new IceStormBullet()); //output:Change magic ==> Ice Storm player.magic(); //output:use Ice Storm //change magic player.changeMagicSystem(new LightningBullet()); //output:Change magic ==> Lightning player.magic(); //output:use Lightning } } }
Publish it!!!
If there is no typing error,you will see those output information.
output:
use Fire Ball
Change magic ==> Ice Storm
use Ice Storm
Change magic ==> Lightning
use Lightning
Example file:
Strategy_Pattern.rar
Reference:
邦邦的部落格 - Design Patterns - 策略模式
wikipedia -Strategy pattern
.
vimax is a herbal medicine devoted to the men, who serves as the vimax canada permanent and extend appropriate in want, quickly and accurately without side effects and with permanent results, vimax asli has been the choice of international consumers. Vimax PiIls already well known parts of the world and is often used by men to increase male virility and maximize the size of the penis, in order to give satisfaction to their partners. obat pembesar penis Vimax has been recognized by scientists the world as an herbal remedy for pembesar penis and how this increase is no longer a secret mighty man, this is extraordinary usefulness fast, mutually agree and permanent.
ReplyDeleteMachine Learning Projects for Final Year machine learning projects for final year
DeleteDeep Learning Projects assist final year students with improving your applied Deep Learning skills rapidly while allowing you to investigate an intriguing point. Furthermore, you can include Deep Learning projects for final year into your portfolio, making it simpler to get a vocation, discover cool profession openings, and Deep Learning Projects for Final Year even arrange a more significant compensation.
Python Training in Chennai Project Centers in Chennai
Terimakasih, semoga admin sukses selalu
ReplyDeleteObat Pembesar Penis
Vimax
Vimax Asli
Vimax Canada
Vimax Original
Obat Vimax
Agen Vimax
Vimax Asli Canada
obat aborsi
ReplyDeletejual obat aborsi
obat penggugur kandungan
cara menggugurkan kandungan
Terimakasih
ReplyDeleteAgen Klg Asli Obat Pembesar Penis Klg Pills Herbal
Agen Klg Asli
Klg
Klg asli
Klg Pills
Klg Herbal
Obat Klg
Agen Klg
Harga Klg
This post was really useful for me, thanks a lot.
ReplyDeleteIklan Gratis
Pasang Iklan
Pasang Iklan Gratis
Jual Vimax Asli Di Batam
ReplyDeleteVimax Asli Di Batam
Jual Vimax Asli Canada Di Batam
Jual Vimax Di Batam
Agen Vimax Asli Di Batam
Vimax Asli Batam
Vimax Di Batam
Agen Vimax Di Batam
Toko Vimax Asli Di Batam
Alamat Toko Vimax Di Batam
Vimax Batam
Ciao a tutti, questo è molto interessante e molto creativo. Spero che ci sia una buona risposta da voi, Grazie desain rumah minimalis
ReplyDeletethank you boss the article really helped us, we wait for the boss's inspiration again. thank you
ReplyDeleteHammer Of Thor Di Bandung
Jual Hammer Of Thor Di Bandung
Vimax Di Bandung
Jual Vimax Di Bandung
Penirum Di Bandung
Jual Penirum Di Bandung
Testo Ultra Di Bandung
Jual Testo Ultra Di Bandung
Klg Di Bandung
Jual Klg Di Bandung
Titan Gel Di Bandung
Jual Titan Gel Di Bandung
Proextender Di Bandung
Jual Proextender Di Bandung
ReplyDeleteVakum Penis Di Bandung
Jual Vakum Penis Di Bandung
Vakum Bathmate Hydromax Di Bandung
Jual Vakum Bathmate Di Bandung
Viagra Di Bandung
Jual Viagra Di Bandung
Extenze Di Bandung
Jual Extenze Di Bandung
Thank you for the information from the article, hopefully it will be useful for us all, the more successful it will be
ReplyDeleteTitan Gel Asli
Parfum Perangsang Wanita
Obat Kuat Viagra Asli
Titan Gel Gold
Harga Titan Gel
Efek samping Titan Gel
Obat Vmenplus asli
Perbedaan Titan Gel hitam Dan Titan Gold
I recommend iDealshare VideoGo as the most professional audio converter and video converter.https://www.idealshare.net/3ga-to-mp3-converter.html
ReplyDelete