Slide 1

Slide 1 text

Design Patterns: The Registry Pattern Ben Ramsey Atlanta PHP • 5 Feb 2009

Slide 2

Slide 2 text

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

Slide 3

Slide 3 text

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

Slide 4

Slide 4 text

Patterns We’ve Discussed • Singleton • Factory

Slide 5

Slide 5 text

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

Slide 6

Slide 6 text

No content

Slide 7

Slide 7 text

No content

Slide 8

Slide 8 text

Example Usage

Slide 9

Slide 9 text

No content

Slide 10

Slide 10 text

The downside (or upside) is you have to pass the Registry object around.

Slide 11

Slide 11 text

Singleton Registry • The store itself is a singleton • Truly “global” data store • No need to pass registry around, exists in all scopes

Slide 12

Slide 12 text

No content

Slide 13

Slide 13 text

No content

Slide 14

Slide 14 text

Example Usage

Slide 15

Slide 15 text

No content

Slide 16

Slide 16 text

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