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.
- 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.
- 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.
- 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.
- 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!
- Ensure the full program works (using SimpleLinkedList with
your adapter in place of SimpleQueue).
- 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.
- 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.
- 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.