In accordance with the concepts expressed in the introduction, I’m going to demonstrate how to implement the interpreter pattern by developing a simple mechanism which will come in handy for processing basic string literals. Essentially, I’m going to define a class which will perform a few useful tasks. These tasks will include loading and saving an inputted string to a specified text file, as well as calculating the length of the string in question. As you can see, all these tasks sound fairly easy to execute, meaning that the structure of this string processing class is very simple. And speaking of that, here is the definition for this class, so take a look at its source code: // define 'StringSaver' class Not surprisingly, the signature that corresponds to the previous “StringSaver” class is really easy to grasp. As I said before, the tasks performed by this class are limited to loading and saving a given string to a target text file, along with returning the length of that string to calling code. However, at this point there’s not a single clue about how to include an interpreter class that can work in conjunction with the string processor that you learned a few lines above. In the next section, I’m going to define the basic structure of an interpreter class, in this way implementing the programmatic model dictated by the homonymous pattern. Having said that, and assuming that you’re interested in learning how this interpreter class will be built, I suggest you click on the link that appears below and read the following section.
blog comments powered by Disqus |