Design Patterns / Week 5

Spell checking, word counting...Spell checking, word counting…

We shall remember the document structure. How an we implement document processing operations, such as spell and grammar checking, text searching, word counting, translation in another language, text to speech and so on? We want to have an extensible design in order to easily add new operations requested by end-users.

Except for trivial cases, document processing operations need to implement complex algorithms that will access all the objects of the document (at least once) and will apply appropriate processing on each visited element. Thus, we better split the implementation of these operations in two parts: (1) traversing the structure and (2) performing the tasks. For the first part, Iterator pattern is our friend. For the second job, we may consider an implementation based on Visitor pattern.

Ok, got it! Iterators and visitors will do the job…. but for loading a document into memory from a persistent support (such as a file) we don’t have the object structure yet… We’ll need a creational pattern to construct it. Our document is represented in memory by a complex collection of linked objects that one needs to create from a byte stream (the input file); and we need to support different file types (XML, RTF, PDF etc). Builder pattern is gracefully helping us for this task.

Want to learn more? Click here for details.

This entry was posted in Design Patterns and tagged , , , , . Bookmark the permalink.