As I expressed in the section you just read, to complete the programmatic model imposed by the stage pattern, it's necessary to build a contextual class capable of selecting the appropriate CSS style that fits the requirements of a specific web document. To perform this simple task, below I defined the brand new "CSSContext" class. It is responsible for returning the correct CSS object to client code in response to the format demands of a given web page. Now that I have explained how this contextual class is going to work, please pay attention to its respective signature: // define 'CSSContext' class As I said before, the above class has been provided with the capacity to create a specific CSS object in accordance with the format requirements of a particular web document. As you can see, this task is performed by its "getCSS()" method, which returns to calling code either a CSS object suitable for use with computer monitors, or another one for use with printers. All right, at this stage I have defined a contextual class that controls what type of CSS object must be used according to the specifications of a given web document. However, there's a missing piece in this scenario, since I need to create a mechanism that generates the web document in question. In response to this requirement, below I included the definition of a brand new class. It's called "WebPage," and it is tasked with creating web pages on the fly, using a specific CSS object passed as an input parameter to the corresponding constructor. The signature for the aforementioned class is as follows: // define 'WebPage' class Now that you have seen the definition for the above "WebPage" class, I'm pretty certain that you'll see more clearly how the stage pattern is implemented in this case. Let me explain the situation briefly: on one hand, there's a contextual class that selects the proper CSS object to be used when generating a web document, while on the other hand there's another class that changes its behavior -- notice the implementation of the "makeBody()" method -- to fit the requirements of a particular page format. Okay, at this point you hopefully understand how the stage pattern is used here. However, I think that you'll grasp the way that this pattern works even more easily if I set up a concrete example where all the previous classes are put to work in conjunction. In the following section I'm going to develop a short script that will help to demonstrate the functionality of the stage pattern. Keep reading, please.
blog comments powered by Disqus |