As I stated in the beginning, implementing the memento pattern requires at least two independent classes. Therefore, the first step that I'm going to take will consist of defining one of the primary classes that comprises the structure of this pattern. I'm referring to the originator element, which in this case is aimed at building a comprehensive file reading class. Meanwhile, the caretaker class that I plan to create will be capable of holding the value of one particular property that belongs to this file reader, in this manner implementing a basic file navigation mechanism. Now that I've outlined the general structure of the originator class, you'll want to take a look at its corresponding signature: // define 'FileDataReader' class (in this case, this is the As you can see, the above "FileDataReader" class is capable of performing some useful tasks, with reference to reading data from a specified text file. As to the functionality of this class, you'll realize that it's capable of fetching file data as an array structure, as well as retrieving one line of that file at once. Not too bad, right? However, while I have to admit that the previous file reading class isn't going to change your life as a PHP developer, it does show in a nutshell how to define the structure of an originator. Naturally, any class can potentially fall under that category, but in this case the "FileDataReader" class is more than enough to demonstrate the functionality of the memento pattern. At this stage, I'm pretty certain that you grasped the logic that drives the originator class. Therefore, in the following section I'll show you how to create the corresponding caretaker class. As I said when I explained how the caretaker class works, it will be capable of maintaining the value of a specific property. To learn how this brand new class will be created, please click on the link shown below and keep reading.
blog comments powered by Disqus |