A good point to start demonstrating an approachable implementation of the template pattern consists of defining a basic file processing class, which will be used later on by a template object to display contents fetched from a specific target file. As you'll see, the file contents will be displayed either in (X)HTML and XML format or as an uppercased string, depending on which template class will be used for this purpose. So far there's nothing unexpected, right? Now that you know the reasons for using a template object, please pay attention to the signature of the file processing class. It looks like this: // define 'FileProcessor' class As illustrated above, the logic followed by the previous "FileProcessor" class is indeed very easy to understand. In crude terms, all that this class does is read and write data to a specified target file, in addition to determining the size of this file by using its simple "getFileSize()" method. However, as you might have guessed, the previous class isn't the main objective of this tutorial at all. As I said before, I'm going to use an instance of it, so it can be adequately processed by a template object. Sounds pretty simple, doesn't it? Of course, as you know, the signature of this template class remains undefined, so if you want to see how the template in question will look, please click on the link below and keep reading.
blog comments powered by Disqus |