Home arrow PHP arrow Checking Email Addresses with the Strategy Design Pattern

Checking Email Addresses with the Strategy Design Pattern

In this fourth part of a series on the strategy design pattern, I extend the functionality of the sample validation program by adding another strategy class to it. The new class will check the validity of a supplied email address.

TABLE OF CONTENTS:
  1. Checking Email Addresses with the Strategy Design Pattern
  2. Review: validating input data with the Strategy design pattern
  3. Building a strategy class for validating email addresses
  4. The EmailValidator class as a standalone component
By: Alejandro Gervasio
Rating: starstarstarstarstar / 1
April 26, 2010

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

As you may have heard, the Strategy design pattern is a software design paradigm that allows developers to build flexible and modular applications by taking advantage of the functionality offered by Composition, rather than relying heavily on the benefits brought by Inheritance. While this may sound like an obscure and hard-to-grasp concept, the truth is that implementing the Strategy pattern is a straightforward process. It's even easier to accomplish when using a programming language as friendly as PHP.

Quite possibly, one of the most challenging aspects that surround the implementation of the Strategy pattern in PHP is to demonstrate how to apply it in a "real-world" use case. Many of the tutorials that cover the topic very often appeal to "toy code examples," which aren't of great help, especially when trying to solve problems present in real environments.

In an attempt to tackle the subject from a realistic point of view, in this article series you'll learn in a step-by-step fashion how to use the Strategy pattern to build a scalable PHP application. This application will be able to check different types of incoming data, including integer and float numbers, email addresses and URLs, without having to use a monolithic God class.

In the last tutorial I left off explaining how to use the power of the Strategy pattern to define an easily-customizable class which validates float numbers in a simple manner. Its loosely-coupled nature makes it possible to use the class as a part of a more complex validation strategy in conjunction with other classes, or as a standalone component.

The primary goal of this series of articles is to develop a flexible and scalable program that can validate supplied data via a set of different strategy classes that can be easily assembled at run time. So, in the following lines I'm going to expand the program's current functionality by adding an entirely new strategy class to it, which will check the validity of a provided email address.

Are you ready to continue learning how to implement the Strategy pattern to validate incoming data? Then begin reading right now!



 
 
>>> More PHP Articles          >>> More By Alejandro Gervasio
 

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

PHP ARTICLES

- Hackers Compromise PHP Sites to Launch Attac...
- Red Hat, Zend Form OpenShift PaaS Alliance
- PHP IDE News
- BCD, Zend Extend PHP Partnership
- PHP FAQ Highlight
- PHP Creator Didn't Set Out to Create a Langu...
- PHP Trends Revealed in Zend Study
- PHP: Best Methods for Running Scheduled Jobs
- PHP Array Functions: array_change_key_case
- PHP array_combine Function
- PHP array_chunk Function
- PHP Closures as View Helpers: Lazy-Loading F...
- Using PHP Closures as View Helpers
- PHP File and Operating System Program Execut...
- PHP: Effects of Wrapping Code in Class Const...

Developer Shed Affiliates

 


Dev Shed Tutorial Topics: