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

Design Patterns: The Registry Pattern (Atlanta PHP February 2009)

Design Patterns: The Registry Pattern (Atlanta PHP February 2009)

Presented as a mini-topic talk at the February 2009 Atlanta PHP user group meeting.

0c217b9a7dd0aa31ed40bd0f453727e1?s=128

Ben Ramsey
PRO

February 05, 2009
Tweet

Transcript

  1. Design Patterns: The Registry Pattern Ben Ramsey Atlanta PHP •

    5 Feb 2009
  2. What Is a Design Pattern? “A design pattern is a

    general reusable solution to a commonly occurring problem in software design. ...”
  3. What Is a Design Pattern? “... A design pattern is

    not a finished design that can be transformed directly into code. It is a description or template for how to solve a problem that can be used in many different situations.” -- Wikipedia
  4. Patterns We’ve Discussed • Singleton • Factory

  5. Registry Pattern • Application data store • Acts as a

    “dictionary” of name/value pairs of data • Can contain scalars, arrays, objects, etc. • Pass it around to have a more-or-less “global” data store; sensitive to scope
  6. None
  7. None
  8. Example Usage

  9. None
  10. The downside (or upside) is you have to pass the

    Registry object around.
  11. Singleton Registry • The store itself is a singleton •

    Truly “global” data store • No need to pass registry around, exists in all scopes
  12. None
  13. None
  14. Example Usage

  15. None
  16. Criticism • The Registry is a kind of global variable;

    global variables create code smell • Martin Fowler advocates the use of static methods for the Registry; this creates mixed feelings in developer communities