ESOF 427
Software Design and Architecture
Fall 2014

Montana Tech
Computer Science & Software Engineering

Prefix completion, refactoring

The goal of this assignment is learn to refactoring existing code to achieve strategic closure under expected axes of change.


Your company has an existing class that stores a vocabulary of words in a trie data structure. The class is designed to support a predictive keyboard that auto-completes a word based on the currently entered prefix entered by the user. The trie tracks usage stats about how often a user has auto-completed using a particular word in the trie. It tracks the number of times a word has been used and the timestamp of the most recent use.

In the first instance, the vocabulary is loaded from a file that simply contains a word on each line. This allows us to bootstrap from a simple list of words. Thereafter, the data file always contains three whitespace separated items per line: Currently the class supports reading/writing from/to a plain text file, a gzipped text file, or a zipped text file. The data file is read when the VocabTrie object is constructed. An updated version of the trie is dumped to disk if someone calls the write method. The clients of VocabTrie currently request matching words in three different ways: The file format and the result matching word filtering is currently controlled by two enumerated types that are passed into the constructor. As shown in the UML diagram below, VocabTrie has gotten a bit out of hand, mixing details about file I/O and result filtering with its main job of representing the trie. This is a clear violation of the single responsibility principle.

Your currently first expected axis of change is how the file is stored. For example, you can imagine management may ask for reading/writing bzip2 files, encrypting files, or storing files in the cloud. Your second expected axis of change is how clients may want results sorted or filtered. For example, you can imagine being asked to return the top-5 matching words by usage, or returning 5 words with 4 being the top used words and the last being the most frequently used.

You need to refactor VocabTrie to close the class for modification to the file storage mechanism and the details of how the client would like the results filtered/sorted. That is, it should be easy to extend to a new compression technique or result filtering requirement by extending classes rather then modifying existing ones. The exact details are part of the adventure, but you should probably consider the strategy pattern.

To get started, downloaded a zip of the Eclipse project: This includes all the source code from the above diagram, as well as a test program and the associated support files. Start by verifying all unit test are passed.
Submission. Please submit a zip to the Moodle dropbox containing your Eclipse directory containing your refactored implementation. You should provide a modified version of my JUnit test program that provides similar test coverage to my original test suite. All tests should be green.

Page last updated: October 02, 2014