HomePHP Handling File Data with the Facade Pattern in PHP 5
Handling File Data with the Facade Pattern in PHP 5
Are you interested in learning the foundations of different structural patterns in PHP 5? If your answer is affirmative, then you should start reading this article immediately! Welcome to the last installment of the series “Introducing the Facade Pattern in PHP 5.” In two consecutive articles, this series shows you how to create and use facade classes in PHP-based development environments.
As you know, PHP 5 allows you to create web applications that implement a diverse range of design patterns, logically including that one called “facade.” If you’ve not yet read the first part of this series and don’t know what this pattern is about, then let me offer you a brief introduction.
Essentially, in the facade pattern a class is created in such a way that it’s able to hide all the complexity inherent to a given mechanism, in order to perform a specific task. This mechanism (usually comprised of one or more classes) is completely independent from the calling class, and knows nothing about it. As you might guess, even though this theoretical definition may sound a bit complex, the truth is that creating facade classes with PHP 5 is an easy process.
To clarify possible questions on how this pattern works, in the first part of the series I worked in a step-by-step format to define a simple façade class. The class was capable of compressing a diverse range of contents, including all the source code created by a web page generator class.
The most important part of this facade class was logically the one related to hiding all the complexity involved in compressing the (X)HTML output of different web documents by using a pair of additional classes. In accordance with the logic dictated by the pattern, these supporting classes were entirely independent of the facade. They were tasked only with compressing any number of input strings passed as parameters to a specific method.
Now that you hopefully recalled the topics covered in the preceding article, it’s time to pay attention to the subject of this one. I’m going to continue demonstrating the application of the facade pattern, this time by developing yet another illustrative application. It will take care of processing the contents of a selected data file in different ways.
So how does a facade class fit into this schema? Start reading to find out!