16
11/05/22 Juan Carlos Giraldo Cardozo Programación Multimedia

Factory Method Pattern

  • Upload
    jucagi

  • View
    2.559

  • Download
    0

Embed Size (px)

DESCRIPTION

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

Citation preview

Page 1: Factory Method Pattern

10/04/23Juan Carlos Giraldo Cardozo Programación Multimedia

Page 2: Factory Method Pattern

Contenido

10/04/23Juan Carlos Giraldo Cardozo Programación Multimedia

Page 3: Factory Method Pattern

Design Patterns• Describing recurring

solutions to common problems in software design.

• the capabilities and pitfalls of object-oriented programming,

• and describing 23 classic software design patterns.

10/04/23Juan Carlos Giraldo Cardozo Programación Multimedia

Page 4: Factory Method Pattern

23 classic software design patterns.• Creational

patterns▫ Abstract▫ Builder▫ Factory Meth

od▫ Prototype▫ Singleton

• Structural patterns▫ Adapter▫ Bridge▫ Composite▫ Decorator▫ Facade▫ Flyweight▫ Proxy

• Behavioral patterns▫ Chain of responsi

bility▫ Command▫ Interpreter▫ Iterator▫ Mediator▫ Memento▫ Observer▫ State▫ Strategy▫ Template method▫ Visitor

10/04/23Juan Carlos Giraldo Cardozo Programación Multimedia

Page 5: Factory Method Pattern

Creational patterns

•These patterns have to do with class instantiation. ▫class-creation patterns and (use

inheritance effectively)▫object-creational patterns (use delegation)

10/04/23Juan Carlos Giraldo Cardozo Programación Multimedia

Page 6: Factory Method Pattern

Creational patterns•Abstract Factory groups object factories

that have a common theme.•Builder constructs complex objects by

separating construction and representation.

•Factory Method creates objects without specifying the exact class to create.

•Prototype creates objects by cloning an existing object.

•Singleton restricts object creation for a class to only one instance.

10/04/23Juan Carlos Giraldo Cardozo Programación Multimedia

Page 7: Factory Method Pattern

Factory Method

10/04/23Juan Carlos Giraldo Cardozo Programación Multimedia

Page 8: Factory Method Pattern

The factory method pattern

•is an object-oriented design pattern. • it deals with the problem of creating

objects (products) without specifying the exact class of object that will be created.

•defining a separate method for creating the objects

•which subclasses can then override to specify the derived type of product that will be created.

10/04/23Juan Carlos Giraldo Cardozo Programación Multimedia

Page 9: Factory Method Pattern

ActionScript applicationsthat have multiple classespublic class Client{

public function doSomething( ){

var object:Object = new Product( );object.manipulate( );

}}

10/04/23Juan Carlos Giraldo Cardozo Programación Multimedia

Page 10: Factory Method Pattern

dependency between the Client and Product classes•There’s nothing wrong with this code, but

it does create a coupling or dependency between the Client and Product classes.

•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.

10/04/23Juan Carlos Giraldo Cardozo Programación Multimedia

Page 11: Factory Method Pattern

Model of the Factory Method Pattern

Client Creator Product1 ** 1

uses create

10/04/23Juan Carlos Giraldo Cardozo Programación Multimedia

Page 12: Factory Method Pattern

public class Creator{

public static function simpleFactory(product:String)

{if (product == "p1"){

return new product1( );} else if (product == "p2") {

return new product2( );}

}}

10/04/23Juan Carlos Giraldo Cardozo Programación Multimedia

Page 13: Factory Method Pattern

Classic factory method pattern

10/04/23Juan Carlos Giraldo Cardozo Programación Multimedia

Page 14: Factory Method Pattern

Classic factory method pattern

• Interfaces and not concrete classes•A pure interface does not provide any

implementation for declared methods. •Abstract interfaces can provide default

implementations for methods. •They’re also called abstract classes, and

cannot be instantiated, but can be extended by other classes.

10/04/23Juan Carlos Giraldo Cardozo Programación Multimedia

Page 15: Factory Method Pattern

Singleton pattern• is a design pattern that is used to restrict

instantiation of a class to one object. •This is useful when exactly one object is

needed to coordinate actions across the system.

•Sometimes it is generalized to systems that operate more efficiently when only one or a few objects exist.

• It is also considered an anti-pattern since it is often used as a euphemism for global variable.

10/04/23Juan Carlos Giraldo Cardozo Programación Multimedia

Page 16: Factory Method Pattern

Singleton pattern

10/04/23Juan Carlos Giraldo Cardozo Programación Multimedia