HomePHP The Singleton and Factory Patterns in PHP: Building object-oriented forms
The Singleton and Factory Patterns in PHP: Building object-oriented forms
Experienced PHP programmers know that web development problems are often tackled by using widely known design patterns within the context of an application. This article is the first in a series that will demonstrate how the Singleton and Factory patterns can be implemented in a real-world application.
Many web developers around have started to use extensively object-oriented programming in PHP applications. Due to the fact that this approach requires a radical change in the way that situations are solved within a program, it takes a while to get an intimate grounding in this paradigm.
Going one step further, for PHP programmers with a certain level of experience, the use of widely known design patterns within the context of an application is definitely a common method for tackling many problems inherent in web development. Since design patterns are key concepts involved in software engineering, mastering them directly implies having a strong knowledge about their theory and practical implementation.
Of course, through this series, I'm not going to offer a detailed definition of the most used design patterns, since there's all sorts of clever information on the subject in many good books and rich-content articles that thoroughly cover the topic. Instead, the primary goal of this series is to demonstrate how the Singleton and Factory patterns can be implemented in a real-world application, without the need to incur in the use of rather impractical examples.
If you've read the article's title, surely know what I'm talking about. I'll apply the above mentioned design patterns to building web forms, by utilizing an object-oriented approximation. Hopefully, the overall experience will be useful enough to teach how (X)HTML forms can be created by relying strongly on these two familiar patterns.
However, if you're just starting to learn about the topic, don't feel concerned. I'll cover briefly the corresponding definition for the Singleton and Factory Patterns, in order to help you clearly understand how they are used.
All right, once we've introduced ourselves to the field of design patterns in PHP, it's time to learn more about them. Thus, let's get started.