As I said in the beginning of this article, my demonstration of how to implement the stage pattern with PHP 5 will consist mainly of creating a simple mechanism that generates dynamically two different versions of a given web document. The first one will be best suited for use with conventional computer monitors, and the second one will be simply a "printer-friendly" format of the document in question. Of course, as you might have guessed, selecting the proper CSS styles that fit a particular web page format will be a task performed by two concrete classes, in this case called "CSSNormal" and "CSSPrint" respectively. The signatures corresponding to these two concrete classes are shown below, including the pertinent definition of their parent. Having said that, the classes look like this: // define abstract 'CSS' class // define concrete 'CSSNormal' class // define concrete 'CSSPrint' class As you can see, the concrete classes listed above are very easy to grasp. Basically, their primary task is to create a CSS style that suits the requirements of a particular web page format. In the first case, the "CSSNormal" class is tasked with building a CSS style that's best suited for use with computer screens, while the second class, called "CSSPrint," is obviously responsible for creating a set of styles for use with printers. So far, so good. At this point I have built two simple classes that are capable of generating diverse CSS styles for applying to a specific web document. However, at this moment I'm sure you're asking the following question: how does the stage pattern fit into this schema? I'm glad you asked! Having at our disposal the two classes previously defined, I'm going to create a contextual class. It will be able to change its behavior in order to select a specific CSS style according to the format requirements of a given web page. In doing so, I'll be implementing the model demanded by the stage pattern. Naturally, this brand new contextual class will be defined in the following section, therefore click on the link that appears below and keep reading.
blog comments powered by Disqus |