Factory Method Pattern

2,862 views

Published on

Presentación sobte el patrón de diseño Factoria en ActionScript 3.0

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
2,862
On SlideShare
0
From Embeds
0
Number of Embeds
15
Actions
Shares
0
Downloads
109
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Factory Method Pattern

  1. 1. 02/06/09 Juan Carlos Giraldo Cardozo Programación Multimedia
  2. 2. Contenido 02/06/09 Juan Carlos Giraldo Cardozo Programación Multimedia
  3. 3. Design Patterns <ul><li>Describing recurring solutions to common problems in software design. </li></ul><ul><li>the capabilities and pitfalls of object-oriented programming, </li></ul><ul><li>and describing 23 classic software design patterns . </li></ul>02/06/09 Juan Carlos Giraldo Cardozo Programación Multimedia
  4. 4. 23 classic software design patterns . <ul><li>Creational patterns </li></ul><ul><ul><li>Abstract </li></ul></ul><ul><ul><li>Builder </li></ul></ul><ul><ul><li>Factory Method </li></ul></ul><ul><ul><li>Prototype </li></ul></ul><ul><ul><li>Singleton </li></ul></ul><ul><li>Structural patterns </li></ul><ul><ul><li>Adapter </li></ul></ul><ul><ul><li>Bridge </li></ul></ul><ul><ul><li>Composite </li></ul></ul><ul><ul><li>Decorator </li></ul></ul><ul><ul><li>Facade </li></ul></ul><ul><ul><li>Flyweight </li></ul></ul><ul><ul><li>Proxy </li></ul></ul><ul><li>Behavioral patterns </li></ul><ul><ul><li>Chain of responsibility </li></ul></ul><ul><ul><li>Command </li></ul></ul><ul><ul><li>Interpreter </li></ul></ul><ul><ul><li>Iterator </li></ul></ul><ul><ul><li>Mediator </li></ul></ul><ul><ul><li>Memento </li></ul></ul><ul><ul><li>Observer </li></ul></ul><ul><ul><li>State </li></ul></ul><ul><ul><li>Strategy </li></ul></ul><ul><ul><li>Template method </li></ul></ul><ul><ul><li>Visitor </li></ul></ul>02/06/09 Juan Carlos Giraldo Cardozo Programación Multimedia
  5. 5. Creational patterns <ul><li>These patterns have to do with class instantiation. </li></ul><ul><ul><li>class-creation patterns and (use inheritance effectively) </li></ul></ul><ul><ul><li>object-creational patterns (use delegation) </li></ul></ul>02/06/09 Juan Carlos Giraldo Cardozo Programación Multimedia
  6. 6. Creational patterns <ul><li>Abstract Factory groups object factories that have a common theme. </li></ul><ul><li>Builder constructs complex objects by separating construction and representation. </li></ul><ul><li>Factory Method creates objects without specifying the exact class to create. </li></ul><ul><li>Prototype creates objects by cloning an existing object. </li></ul><ul><li>Singleton restricts object creation for a class to only one instance. </li></ul>02/06/09 Juan Carlos Giraldo Cardozo Programación Multimedia
  7. 7. Factory Method 02/06/09 Juan Carlos Giraldo Cardozo Programación Multimedia
  8. 8. The factory method pattern <ul><li>is an object-oriented design pattern . </li></ul><ul><li>it deals with the problem of creating objects (products) without specifying the exact class of object that will be created. </li></ul><ul><li>defining a separate method for creating the objects </li></ul><ul><li>which subclasses can then override to specify the derived type of product that will be created. </li></ul>02/06/09 Juan Carlos Giraldo Cardozo Programación Multimedia
  9. 9. ActionScript applications that have multiple classes <ul><li>public class Client </li></ul><ul><li>{ </li></ul><ul><ul><li>public function doSomething( ) </li></ul></ul><ul><ul><li>{ </li></ul></ul><ul><ul><ul><li>var object:Object = new Product( ); </li></ul></ul></ul><ul><ul><ul><li>object.manipulate( ); </li></ul></ul></ul><ul><ul><li>} </li></ul></ul><ul><li>} </li></ul>02/06/09 Juan Carlos Giraldo Cardozo Programación Multimedia
  10. 10. dependency between the Client and Product classes <ul><li>There’s nothing wrong with this code, but it does create a coupling o r dependency between the Client and Product classes. </li></ul><ul><li>Any changes to the Product class in terms of class name changes or change in the number of parameters passed to it will require changes in the Client class as well. </li></ul>02/06/09 Juan Carlos Giraldo Cardozo Programación Multimedia
  11. 11. Model of the Factory Method Pattern 02/06/09 Juan Carlos Giraldo Cardozo Programación Multimedia Client Creator Product 1 * * 1 uses create
  12. 12. <ul><li>public class Creator </li></ul><ul><li>{ </li></ul><ul><ul><li>public static function simpleFactory(product:String) </li></ul></ul><ul><ul><li>{ </li></ul></ul><ul><ul><ul><li>if (product == &quot;p1&quot;) </li></ul></ul></ul><ul><ul><ul><li>{ </li></ul></ul></ul><ul><ul><ul><li>return new product1( ); </li></ul></ul></ul><ul><ul><ul><li>} else if (product == &quot;p2&quot;) { </li></ul></ul></ul><ul><ul><ul><li>return new product2( ); </li></ul></ul></ul><ul><ul><ul><li>} </li></ul></ul></ul><ul><ul><li>} </li></ul></ul><ul><li>} </li></ul>02/06/09 Juan Carlos Giraldo Cardozo Programación Multimedia
  13. 13. Classic factory method pattern 02/06/09 Juan Carlos Giraldo Cardozo Programación Multimedia
  14. 14. Classic factory method pattern <ul><li>Interfaces and not concrete classes </li></ul><ul><li>A pure interface does not provide any implementation for declared methods. </li></ul><ul><li>Abstract interfaces can provide default implementations for methods. </li></ul><ul><li>They’re also called abstract classes, and cannot be instantiated, but can be extended by other classes. </li></ul>02/06/09 Juan Carlos Giraldo Cardozo Programación Multimedia
  15. 15. Singleton pattern <ul><li>is a design pattern that is used to restrict instantiation of a class to one object . </li></ul><ul><li>This is useful when exactly one object is needed to coordinate actions across the system. </li></ul><ul><li>Sometimes it is generalized to systems that operate more efficiently when only one or a few objects exist. </li></ul><ul><li>It is also considered an anti-pattern since it is often used as a euphemism for global variable . </li></ul>02/06/09 Juan Carlos Giraldo Cardozo Programación Multimedia
  16. 16. Singleton pattern 02/06/09 Juan Carlos Giraldo Cardozo Programación Multimedia

×