SE 2811, Hasker's Section, Exercise 2
Applying the adapter pattern

Note 2 describes the adapter pattern. You will use this pattern to adapt a program to use a different type of queue. Feel free to consult with other students on this exercise.

  1. Download QueueApplication.java and SimpleQueue.java and get this code to run in IntelliJ. This is intended to simulate having a large program that uses queues for basic processing. You can add package declarations if you like, but it is not required.
  2. Someone gets the bright idea to change QueueApplication.java to use a linked list for the queue. You find SimpleLinkedList.java laying around the shop, and you realize that a linked list can be used to implement a queue (since adding to the end and removing from the front are both O(1) operations), and so decide to use the Adapter pattern to use this instead of SimpleQueue.
  3. Create an interface class and revise QueueApplication and (the existing) SimpleQueue to work as before. That is, you are rewriting the application to introduce (throughout the application) a simple queue interface. You will remove SimpleQueue in the next step, but this step makes sure your interface is correct. Taking small steps like this saves time debugging!
  4. Create an adapter class that adapts SimpleLinkedList to work with QueueApplication. You should not need to change SimpleLinkedList.java. Be careful to use good names. Names like "Adapter" and "Interface" are too generic!
  5. Ensure the full program works (using SimpleLinkedList with your adapter in place of SimpleQueue). When you run it, you should see the output
            Testing adding, removing todo items.
            Testing adding, removing many todo items.
            Testing empty todo list.
            All tests passed.
    
  6. Note: if you have copy pasted method implementations from SimpleLinkedList.java to your adapter, talk to your instructor! Your adapter should be using delegation to get the work done.
  7. Submit your solution to esubmit as ex2adapt. Submit your revised version of QueueApplication.java as the Main. Then click on Add file twice to add your interface class and your adapter class. Do not submit SimpleLinkedList.java - that code is already provided for you and you cannot make changes to it. Then click the submit button and confirm there are no differences in the output.

Once you have submitted your solution to esubmit (and there are no differences), you are done with the exercise. There is nothing to submit to Canvas.