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

10 Points

Slide 14 of note 2 describes the adapter pattern. You will use this pattern to adapt a program to use a different type of queue. You can work in pairs 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 can save you a lot of debugging time.
  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).
  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. Make sure your name is in all files. Note that the code will not be graded for meeting standards beyond basic ones like using reasonable names for classes/methods and having your name in the files. In particular, you do not have to add other documentation.
  8. Submit your revised adapter class, your interface class, and your revised version of QueueApplication.java to Canvas

If you are working with a partner, you must both upload your own copies to Canvas.