Archive for the 'Introduction to Design Patterns' Category

PHP Design Patterns: An Introduction

Design Patterns are about Relations Between Participants


What Are Design Patterns?

Design patterns are a way to create excellent OOP programs where update and changes can be made without having to rebuild your site from scratch. In many respects, they are the implementation of OOP principles into several different patterns for common uses. They are not templates but rather strategies for solving common programming problems with OOP.

The Pleasure of Doing Something Well

With PHP 5 (or some build of PHP 5) came a host of OOP structures including abstract classes, interfaces, class and method accessors and other OOP elements that moved PHP closer to an OOP language. Do you need OOP for writing effective and practical code in PHP? No. Will learning OOP make you a better programmer? Yes. Design patterns will make you a superior programmer.

If that doesn’t answer your question of Why bother with OOP or Design Patterns?; then this blog probably isn’t for you—at least now now. If you do derive pleasure in doing something well, all you need are a few OOP and Design Pattern principles and lots of patience with understanding advanced programming concepts. Here are a few OOP principles:

  • A class should only have a single responsibility
  • Strive for loosely coupled objects (classes)
  • Favor composition over inheritance
  • Subclass from interfaces and abstract classes

We’ll be discussing those and other OOP/Design Pattern principles with examples in PHP. The principles apply to all languages, and so if you’re familiar with them from one programming language you’ll find that they apply to PHP as well. The syntax may be different but the principles remain the same.
Continue reading ‘PHP Design Patterns: An Introduction’

Share