Home arrow PHP arrow The Singleton and Factory Patterns in PHP: a rendering-capable factory class

The Singleton and Factory Patterns in PHP: a rendering-capable factory class

In this third part of the series, I will explain how to implement the Factory pattern in conjunction with the polymorphic characteristics of form objects. This will boost the functionality of the factory class by simplifying the process for rendering form elements.

  1. The Singleton and Factory Patterns in PHP: a rendering-capable factory class
  2. The Factory pattern in a real application: a quick look at the “formElementFactory” class
  3. A smarter factory: applying Polymorphism within the “formElementFactory” class
  4. Polishing the Page
By: Alejandro Gervasio
Rating: starstarstarstarstar / 11
November 16, 2005

print this article




Welcome to the third part of the series “The Singleton and Factory Patterns in PHP.” As you probably remember, in the second part of this series, I applied the functionality of the Factory pattern to taking the process of regular form generation from an object-oriented point of view, branching to a different direction from the traditional way for coding web forms.

Essentially, the form generation process can be divided into three key categories: element class definition, form element factory class definition, and finally visual presentation. As you might guess, the first one refers to the stage at which all of the form elements are structured as individual classes, the second implies specifically the definition of the required form factory itself, while the third stage is tasked with rendering each form element according to the specific needs within the program.

So far, I’ve demonstrated a basic implementation of the abstract “formElementFactory” class, which is responsible for creating form element objects, by separating object instantiation from the rest of the application code.

As I mentioned previously in the second part of the series, there are several features that must be added to the logic of the form application, in order to get a more functional version of it, by satisfying several requirements often present in real environments.

Certainly, the first issue to be properly addressed is the rather ineffective implementation of Polymorphism for rendering form elements. The second issue is  the lack of control in the overall presentational layout of the form.

For most of these problems to be efficiently solved, we need to apply some refactoring to the form element factory. We do this by adding the capability to take advantage of the polymorphic features exposed by each form element object, as well as implementing a basic control on the visual presentation for every element.

In this part of the series, I shall provide an overview of the solutions for tackling the above conflicting topics, while maintaining a strong practical approach in the use of design patterns.

So, it’s time to learn more about applying design patterns to object-oriented forms. Let’s get started.

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

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort


- 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: