1 / 10

Factory Method Design Pattern: ActionScript 3.0 Implementation

Factory Method Design Pattern: ActionScript 3.0 Implementation. Bill Sanders Sandlight Productions Bloomfield, Connecticut. Links and Downloads. You will find all materials in .zip folders that you might want to download and open in Flash CS5 or Flex (Flash Builder) to follow along:

thane
Télécharger la présentation

Factory Method Design Pattern: ActionScript 3.0 Implementation

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Factory Method Design Pattern: ActionScript 3.0 Implementation Bill Sanders Sandlight Productions Bloomfield, Connecticut

  2. Links and Downloads • You will find all materials in .zip folders that you might want to download and open in Flash CS5 or Flex (Flash Builder) to follow along: • Download files from here: • http://nemo.mwd.hartford.edu/~wsanders/Brasil/ • You can also test the applications on the play links • Play links: • http://www.sandlight.com/Brasil/ • http://www.sandlight.com/NewEngland/ • All ActionScript 3.0 Design Patterns • http://www.as3dp.com • http://www.sandlight.com

  3. The Factory Method • When building a large project, you may not know all of the objects you will use in the future or how objects may change • The Factory Method was designed so that the Client class makes requests from the Factory (Creator), not knowing the details about the product being created. Client Factory Product

  4. Factory Method Class Diagram

  5. Factory Method File Diagram

  6. Request from Client to Factory (Program to interface; not implementation) private var parana:Factory; -------------- private function doParana(e:MouseEvent) { parana=new MakeParana(); addChild(parana.factoryMethod()); } Factory interface Concrete Factory instance

  7. Abstract Factory (Creator) package { import flash.display.Sprite; import flash.errors.IllegalOperationError; // ABSTRACT Class) public class Factory { protected var product:Product; // ABSTRACT Method (must be overridden in a subclass) public function factoryMethod():Sprite { throw new IllegalOperationError(“must be overridden"); return null; } } }

  8. Concrete Factory with Lazy Instantiation package { import flash.display.Sprite; public class MakeParanaextends Factory { public override function factoryMethod():Sprite { if(! product) { product=new ParanaProd(); } return product.getObject(); } } } Lazy instantiation

  9. Abstract Product package { import flash.display.Sprite; import flash.errors.IllegalOperationError; // ABSTRACT Class (should be subclassed and not instantiated) class Product { protected var objNow:Sprite; public function getObject():Sprite { throw new IllegalOperationError(“must be overridden "); return null; } } }

  10. Concrete Product package { import flash.display.Sprite; public class ParanaProd extends Product { public override function getObject():Sprite { objNow=new Parana(); objNow.x=273.55, objNow.y=276.50; return objNow; } } } Image in Sprite class

More Related