Object Oriented Design Patterns for PHP

Embed Size (px)

Citation preview

Object Oriented Design Patterns for PHP

An introduction of sorts into the world of design patterns for object oriented PHP, as brought to you by Robert Gonzalez.

http://[email protected]

http://www.robert-gonzalez.com/personal/meetups/apache-49-20081218-code.tar.gzhttp://www.robert-gonzalez.com/personal/meetups/apache-49-20081218-presentation.odphttp://www.slideshare.net/RobertGonzalez/object-oriented-design-patterns-for-php-presentation/

Object Oriented Design Patterns for PHP

Who is this Robert dude?

What are design patterns?

How can design patterns help you?

$this->setup();

Object Oriented Design Patterns for PHP

Who is this Robert dude?

Husband and father

Web developer

Self taught

Began learning HTML in 1997

Began learning Perl in 2000

Began learning PHP in 2003

Full time developer for Bay Alarm Company since 2006

PHP freak

Administrator of the PHP Developers Network forums

Frequent contributor to Professional PHP Google group

Chief helper of n00Bs (at work and beyond)

Zend Certified PHP 5 Engineer

Awesome barbecuer

Object Oriented Design Patterns for PHP

What are design patterns?

The words Object Oriented Design repeated on wall paper

An industry buzzword that gets you into meetups

Recurring solutions to common software development challenges

Mind bending algorithms of confusion and indigestion

The words Object Oriented Design repeated on wall paper

An industry buzzword that gets you into meetups

Recurring solutions to common software development challenges

Mind bending algorithms of confusion and indigestion

Object Oriented Design Patterns for PHP

What are design patterns not?

They are not the end all, be all to all of your coding challenges.

They are not a requirement of object oriented programming.

They are not a requirement of good programming.

They are not a substitute for application code and logic.

They are not always the best solution for the job.

They are not always the easiest concept to grasp and/or use.

Object Oriented Design Patterns for PHP

Some common software development challenges:

Building new applications while leveraging existing codebases

Building/enhancing applications securely, quickly and effectively

Integrating new and existing applications

Multiple developers programming the same product

Few developers programming many products

Varying, sometimes unknown, data sources

Varying, sometimes unknown, operating systems

Varying, sometimes unknown, platforms and setups

Object Oriented Design Patterns for PHP

Yeah, this is all well and good. And your presentation so far kicks all kinds of ass, but seriously, what are design patterns really going to do for me?

Let's have a look at some patterns and see ...

Object Oriented Design Patterns for PHP

The Lazy Load Pattern

Lazy loading is the process of delaying the instantiation of an object until the instance is needed.

We all know the mantra, lazy programmers are the best programmers.

Object Oriented Design Patterns for PHP

The Lazy Load Pattern

Object Oriented Design Patterns for PHP

Why the Lazy Load rocks:

Delays resource consumption until it is needed, which may be never

Is relatively easy to understand

Offers an encapsulated means of creating objects

Offers an encapsulated means of storing objects for use later

Did you just see that? Did he just say storing objects for use later?

Object Oriented Design Patterns for PHP

The Registry Pattern

A registry is an object that other objects can use to access data, settings, values and other objects from a sort of internal storehouse.

Object Oriented Design Patterns for PHP

The Registry Pattern