CS350 Software Design

Lab 5: Identify Observer Patterns

Goal:

Learning observer pattern and how it works in Java Swing

Instructions:

The maze game GUI code has three observer patterns embedded. In this lab, you are supposed to identify them.

Submission: Fill out the multiple choice questions on dbLearn. It might be easier to fill out the chart below and then transfer them. Each construct could be used more than once.

Part I. Identify two of the three observer patterns

The three observer patterns are:

OP1: Whenever a key is pressed, the panel responds to it

OP2: Whenever a mapsite (room, door, wall) is entered, the maze will repaint to show the position of ball or prompt “ouch” if a wall is hit.

OP3: Whenever a movement is detected, the command will be saved into the stack.

The four major responsibilities within an observer pattern are:

R1: Maintaining the mapping between subjects and their observers

R2: Subject change notifications

R3: Update the states of observers.

R4: Registering the Observers with Subjects.

According to the given official observer pattern UML class diagram, please filling out the following form to identify the roles of the classes in each observer pattern (note that not all observer patterns follow their official look. J The roles and responsibilities of the classes participating OP1 have been given. Please complete the form for the other two observer patterns. Note that some classes do not take any role of the pattern, but still have a pattern-related responsibility.

You can use your Maze lab code or the code included at https://www.cs.drexel.edu/~jsalvage/Fall2013/CS350/index.html. You should also look at the Maze UI code.

Java construct / OP1
Role(Responsibilities) / OP2
Role(Responsibilities) / OP3
Role(Responsibilities)
JPanel / AbstractSubject (R1, R2)
KeyAdapter (API) / AbstractObserver
MazePanel / ConcreteSubject (R4)
MazeKeyListener in MazePanel / ConcreteObserver (R3)
The EntryListener Reference in MazePanel
MapSite
EntryListerner (Class Definition)
MazeMoveListener
MazeMover
Room
MazeViewer

Responsibilities

R1: Maintaining the mapping between subjects and their observers

R2: Triggering the notifications

R3: Update the states

R4: Registration