Creational Patterns and Abstract Factory - PowerPoint PPT Presentation

1 / 14
About This Presentation
Title:

Creational Patterns and Abstract Factory

Description:

Creational Patterns and Abstract Factory. Eddie Hirko. Nathan Bazzel. Phuong Ngo ... Generic Candy. Concrete Product. Eddie. Client. Students/users. How ... – PowerPoint PPT presentation

Number of Views:49
Avg rating:3.0/5.0
Slides: 15
Provided by: phuon3
Category:

less

Transcript and Presenter's Notes

Title: Creational Patterns and Abstract Factory


1
Creational Patterns and Abstract Factory
  • Eddie Hirko
  • Nathan Bazzel
  • Phuong Ngo
  • Martin Stonebraker

2
Creational Patterns
  • Abstract instantiation process
  • System independent of how objects are created
    composed, and represented
  • Class creational patterns use inheritance to vary
    class instantiation
  • Object creational patterns delegate instantiation
    to another object
  • Focus on defining small behaviors and combining
    into more complex ones

3
Recurring Themes
  • Encapsulate knowledge about which concrete
    classes the system uses
  • Hide how instances of these classes are created
    and put together

4
Advantages
  • Flexibility in what gets created
  • Who created it
  • How it was created and when
  • Configure system with product objects that vary
    in structure and functionality
  • Configuration can be static or dynamic
  • Create standard or uniform structure

5
Examples of Object and Class Creational patterns
  • Factory Method
  • defines an interface for creating objects, but
    lets subclasses decide which classes to
    instantiate
  • Abstract Factory
  • provides an interface for creating families of
    related objects without specifying concrete
    classes
  • Builder
  • separates the construction of a complex object
    from its representation, so the same construction
    process can create different representations
  • Prototype
  • specifies the kind of objects to instantiate
    using a prototypical instance
  • Singleton
  • ensures that a class has only one instance, and
    provides a global point of reference to that
    instance

6
Creational Pattern Summary
  • Use what is flexible for the situation.
  • Easy to make changes
  • Class creational patterns use inheritance
  • Object creational patterns use object

7
Abstract Factory
  • Abstract Factory Object Creational Pattern
  • Provides an interface for creating families of
    related or dependent objects without specifying
    their concrete classes

8
Why use Abstract Factory?
  • If you want to create sets of objects with varied
    attributes
  • If you want to keep the user separate from the
    creation process, for example
  • For example, a tool-kit where the user creates
    objects by selecting characteristics

9
When to use Abstract Factory
  • A system should be independent of how its
    products are created, composed, and represented
  • A system should be configured with one of
    multiple families of products
  • A family of related product objects is designed
    to be used together and you need to enforce this
    constraint
  • You want to provide a class library of products,
    and you want to reveal just their interfaces, not
    their implementations

10
  • A single instance of Concrete Factory is created
    at run-time
  • To create different product objects, clients
    should use a different concrete factory

11
Benefits and Liabilities
  • Isolates concrete classes
  • Makes exchanging product families easy
  • Promotes consistency among products
  • Supporting new kinds of products is difficult

12
Implementation
  • Key players
  • Abstract Factory
  • declares an interface for operation that creates
    abstract product objects
  • Concrete Factory
  • Implements the operation to create product
    objects
  • Abstract Product
  • Declares an interface for a type of product
    object
  • Concrete Product
  • Defines a product object to be created by the
    corresponding concrete factory
  • Implements the Abstract Product interface
  • Client
  • Uses only interfaces declared by Abstract Factory
    and Abstract Product classes

13
  • Key players
  • Abstract Factory
  • Phuong
  • Concrete Factory
  • Martin/Nathan
  • Abstract Product
  • Generic Candy
  • Concrete Product
  • Eddie
  • Client
  • Students/users

14
How Abstract Factory works
Write a Comment
User Comments (0)
About PowerShow.com