SE Department Logo


Overview

For this exercise you are given Java code that has been poorly engineered. Your task is to examine the code and refactor it to use a specific design pattern.

Resources

GoF Pattern Card

Once you have refactored the design to use the required design pattern, complete the GoF pattern card in the refactoring design document. Remember to use context specific names for your classes (i.e. avoid using names like "Context," "Client," "Subject," etc.). You should also write at least 2-3 sentences describing each class's role in the pattern within the context of this system; do not use generic descriptions of the class roles in the pattern (i.e. "This class is the observer," or "This class is the client.").

UML Diagram

Create a UML diagram of your refactored subsystem. Your diagram should completely capture all of the relationships between classes in the subsystem using proper UML notation. Be sure to include the pattern stereotype for any class that is playing a role in the design pattern by including the name of the role in guillemets beneath the name of the class, e.g. <<Context>>

Refactored Source Code

Finally, you should implement the refactoring on the provided source code and include your refactored code as a ZIP file along with your submission.


Subsystem Description

Download the ZIP file containing the source code for the current subsystem. Compile, and run the main application class. If you find it easier to copy the files into an IntelliJ project (or some other IDE), feel free to do so.

Your team has been hired to update and maintain a piece of warehouse management software. The software (which you will find in the ZIP file) includes a set of classes that represent various kinds of products (Toys, Books, Movies, Food) that are stored in the warehouse. In addition, it includes a Warehouse class that stores an inventory of products and provides a set of query methods that can be used to gather information about specific products (e.g. movies by a specific director, toys appropriate for children of a specific age, etc.).

You have been asked to update the software to add the following new query methods:

New types of products are only rarely added to the warehouse's inventory, but new query methods are added all of the time. It is in the best interests of your team to refactor the design to use the Visitor pattern to make adding new queries easier (and in such a way that the Open-Closed Principle is not violated).

For this assignment you must refactor the existing query methods in the Warehouse class to use the Visitor pattern.

In addition, you should choose two of the items from the list above to implement as visitors (for a total of 6 visitors).

Testing Your Refactored Design

You have been provided with a JUnit 4 unit test that tests the existing methods in the Warehouse class. You should not modify the existing tests. Do not delete any of the existing code! Instead, as you create new visitors, you should write a new test for each visitor.

The visitors that duplicate the functionality of the existing methods should make the same assertions.

If you are using IntelliJ, support for JUnit 4 is integrated into the development environment. The JUnit test file will not compile by default in a new project. In IntelliJ, you will need to open the test file in the editor and click to place your cursor on one of the @Test attributes. Then use alt-enter to add JUnit 4 as a dependency to your project. If you are using an IDE other than IntelliJ, you are on your own to figure out how to get JUnit 4 to work with your IDE.


Deliverables

By the time specified in the course schedule, submit your refactored design document, and your refactored source code Visitor Refactoring dropbox.