The goal of this assignment is to gain further experience refactoring existing code to achieve strategic closure under expected axes of change.
You will practice refactoring code towards the factory and strategy design patterns.
Details
After creating a beautifully designed set of classes to support your company's touchscreen keyboard product, you went on vacation for two weeks.
While gone, your manager outsourced some additional development to Elbonia.
Specifically, the following features were added:
Ability to load a sequence of Trace objects from a plaintext file
Each line in the file is assumed to contain all the touch events for a single Trace
Each touch event is separated by a semicolon
Lines starting with # are assumed to be comments
Client must specify whether all the touch events are TouchTime or TouchFinger events
Each TouchTime event is a comma-separated list of the x-coordinate, y--coordinate, and timestamp
Each TouchFinger event is a comma-separated list of the x-coordinate, y--coordinate, timestamp, and finger ID
A rectangular keyboard class
Loads itself from a plaintext file
Each line is the file represents a single key
A key consists of a comma-separated list of the key's character, its x-center, y-center, width, and height
Lines starting with # are assumed to be comments
The spacebar is labeled with an underscore
Given a TraceSequence can determine the sequence of character generated by the sequence
Decoding uses either the average location of a Trace's touch events, the first location, or the last location
Decoding can optionally drop any touch events that are not inside one of the keys on the keyboard
A circular keyboard class
Similar to the RectangleKeyboard except each line defining a key consists of a radius instead of a width and heigh
A basic command line decoder:
Allows a rectangular or circular keyboard to be loaded
Allows a TraceSequence either of TouchTime or TouchFinger events to be loaded
Decodes the sequence using the average, first point, or last point in a given Trace
Decodes either using the nearest key or only using the key the focal point is inside of
Here is the UML diagram of the classes after Elbonia's modifications:
Now that you are back from vacation, your boss wants the following new features:
A hexagonal keyboard
The ability to load traces from a device that only outputs the (x, y) of each touch event
The ability to load traces from a device that outputs the (x, y) of each touch event plus a touch force term
Being a good software engineer, you argue the right thing to do is to refactor and cleanup Elbonia's mess before embarking on any new features.
Your boss grudgingly agrees. So instead of adding any new features, you are to undertake a refactoring of the existing code.
Things on your to do list include:
Consolidate duplicated code (particularly in CircleKeyboard and RectangleKeyboard
and to a lesser extent CircleKey and RectangleKey)
Close your classes as far as possible for additional keyboard layouts and touch event types
Use the factory pattern instead of relying on integer parameter flags
Use the strategy pattern to allow keyboards to have a configurable focal point algorithm and avoid relying on integer parameter flags
There is an existing JUnit test suite that tests most of the functionality of the project.
You should use and update the test suite as you proceed through your refactoring.
To get started, downloaded a zip of the Eclipse project: KeyboardDecoder.zip.
This includes all the source code from the above diagram, as well as the JUnit test suite 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.
NOTE: please include your name(s) in your Eclipse project name as this makes it easier for me to import multiple submissions into my Eclipse.
You should provide a modified version of my JUnit test programs that provide similar test coverage to my original test suite.
All tests should be green.