AS2 and design mode (1) - Simple factory model

xiaoxiao2021-03-06  17

AS2 and design model (1) --- Simple factory model: "People who want to design design model are genius, and learn that he can only be a good craftsman" ---- a high person

Simple factory model is probably the best understanding in all design patterns, no wonder that this rookie can also write articles to introduce it:

Simple factory model is generally operating this: users tell the processor through an interface parameter (integer or String) to tell the processor you want the specific product, then the processor passes if (argu == 0) return new concreteproduct0 (); Else if (arug == 1) Return New ConcreteProduct1 (); Else If (argu == 2) Return New ConcreteProduct2 (); .... What is the manufacture of related products, how? Very good to understand.

Below, I will specifically explain the primary physical demo system I have recently made: there are two top objects in this betting system, one is SceneManager, which is responsible for the switching of the scene, which is equivalent to the place of manufacturers. Another one is to point to the EffectManager object of the IEffect interface class. Waiting for the SceneManager command, what effect is now present, it demonstrates what effect, which is equivalent to acting as the role of our products. Main scenes for initialization code is as follows: import Sdgp.SMag.SceneMag; import Sdgp.SEffect *; fscommand ( "allowscale", false); var SceneManager:. SceneMag = new SceneMag (); var EffectManager: ISEffect = new CS2BallConserve (); // default Demonstration for two goals. SceneManager.init (); EffectManager.init ();

// Scenemag class is used to implement simple factory mode code segment .class sdgp.smag.scenemag extends rcsmag {.... private var mcommag: iscommag; .... public function changeItem (Num: Number): iSeffect {IF (Num == 0) Return New CS2BallConserve (); Else If (Num == 1) Return New CS3BallConserve (); else if (Num == 2) Return New CSMultiballCol (); else if (Num == 3) Return New NEW CszMball (); else {trace ("unfinished items"); return undefined;}}}

// "Manufacturing" This action is excited by the MenuCombo's Change event. Public function msgchange (evt: object): void {.... if (est.target == _ root.Menucombo) {... // Some judgment and Sweeping work .... _root.effectManager = _root.sceneManager.changeitem (_root.Menucombo.selected "; // is to make 哟 ~~~ ... _root.effectManager.init (); _root.fpscombo. enabled = true;

转载请注明原文地址:https://www.9cbs.com/read-41751.html

New Post(0)