Home arrow PHP arrow Verifying Float Values with the Strategy Design Pattern

Verifying Float Values with the Strategy Design Pattern

In this third part of a series on validating incoming data with the strategy design pattern, I create a brand new strategy class that can check whether or not a supplied input value is a float number. The addition of this class extends the capabilities of the sample validation program that Iím building in this series.

TABLE OF CONTENTS:
  1. Verifying Float Values with the Strategy Design Pattern
  2. Review: the sample classes developed so far
  3. Adding a strategy class for checking float numbers
  4. Using the FloatValidator class as a standalone component
By: Alejandro Gervasio
Rating: starstarstarstarstar / 3
April 21, 2010

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

Design patterns are well-known, reusable paradigms that allow developers to solve certain problems in a more efficient way, even though their implementation is flexible and not tied to a specific programming language. Due to their variety, they can be placed in different categories (creation, structural, behavioral, etc.), but their rather fuzzy boundaries tend to create large gray areas between them.

Itís valid to say, though, that a number of patterns can be of great help, especially when developing more flexible and scalable applications. A good example of this is the triad made up of the Decorator, Composite and Strategy patterns, which share a common feature worth stressing here: all of them tend to favor Composition over Inheritance.

Unlike its handy partners Composite and Decorator, which tackle some common software development problems in an elegant and efficient manner at the expense of a steeper learning curve, Strategy is incredibly easy to implement. This becomes even more evident when using a language as friendly as PHP. When applied in an appropriate case, the Strategy pattern is a powerful tool that permits you to merge two of the big pillars of the object-oriented paradigm: first, to use Composition over Inheritance, and second, to encapsulate the concept that varies.

To demonstrate how useful and easy it is to apply the Strategy pattern in a real-world case using PHP, in the two previous tutorials of this series I started building a modular web application. It was tasked with validating incoming data through a set of loosely-coupled strategy classes. So far, I've shown how to provide this sample program with the ability to check integer values via an isolated ďinteger strategyĒ class, but itís necessary to extend the programís current functionality by adding a few more validation classes to it. Therefore, in the following lines Iím going to develop a brand new strategy class, which will be charged with checking whether or not a supplied value is a float number.

Are you ready to learn more about this process? 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: