Upgrade to Pro — share decks privately, control downloads, hide ads and more …

The Factory Pattern Is Not What You Think It Is

The Factory Pattern Is Not What You Think It Is

The factory pattern was not what Doug thought it was a few years ago. Feeling foolish, Doug asked a some co-workers what they knew about the factory pattern. He discovered that he either needs to find some more sophisticated co-workers or the misunderstanding is more common than one might have expected.

In this presentation, Doug will describe and differentiate the factory concept, factory method and abstract factory pattern so that other developers will avoid making the same mistake.

E710a7268891ac8c9c13756fcd28fa5f?s=128

Doug Corbett

June 13, 2017
Tweet

Transcript

  1. The Factory Pattern Is Not What You Think It Is

    By Doug Corbett
  2. What are Patterns?  Proven software design solutions  Apply

    across domains
  3. Why You Should Care  Create more resilient code

  4. Why You Should Care  Create more resilient code 

    Benefit from the wisdom of others
  5. Gang of Four  Authored the first book on software

    design patterns.  23 Patterns  3 Categories Creational Patterns Structural Patterns Behavioral Patterns
  6. Other Influential Books Followed

  7. Creational Patterns 1. Abstract Factory 2. Builder 3. Factory Method

    4. Prototype 5. Singleton
  8. Factory Concept (not a pattern)

  9. Factory Concept (not a pattern)

  10. Factory Concept (not a pattern)  Pros  Separates instantiation

    from representation  It encapsulates class family instantiation  Hides public instantiation  Cons  Caller has to know what it wants to create  It violates the Open/Close principle
  11. Factory Method Pattern  Characteristics  Factories implement an interface

     Specific factory created might not be specified by the caller, but by configuration or IoC container
  12. Factory Method Pattern

  13. Factory Method Pattern  Pros  Consumer has no concrete

    references to factories or objects. Loose coupling.  Initialization can be encapsulated within the factory.  Can prevent instantiation of objects outside the factory.  Cons  Need new factory for each new object
  14. Abstract Factory Pattern  Characteristics  Similar to Factory Method

    pattern  Supports families of objects
  15. Abstract Factory Pattern

  16. Abstract Factory Pattern  Pros  Like Factory Method Pattern,

    but supports factories that can handle families of objects.  Great for supporting extensibility for other departments or third party vendors.  Cons  More complex
  17. Thank you! - Doug Corbett