Homework 3

In this assignment, you are asked to apply the strategy pattern to the obsever pattern such that an object has a choice of algorithms for notifying its observers. The scenario that you must implement is the following:

A Billboard object has 25 Panels arranged in a 5 by 5 grid. Each Panel is observing the state of a single ColorGenerator object that changes its current color every two seconds. Each time the color changes, the ColorGenerator notifies its observers (the Panels) of the new color and they in turn update their color to match the current color. The result is that every two seconds the Billboard as a whole changes its color to match the current color of the ColorGenerator.

Originally, the ColorGenerator updated its observers in order: first Panel 1, then Panel 2, ..., then Panel 25. The visual effect that this generates gets old quickly, and the customers of the company that produces the Billboard complained. As a result, the company has decided to have the ColorGenerator change how it notifies its observers each time it performs an update. For the new release, the company has decided that they want the following behaviors:

  • Update Panels in order: 1–25. (original behavior)
  • Update Panels in reverse order: 25-1.
  • Update Panels in two passes: first odd panels (1, 3, 5, ...) and then even Panels (2, 4, 6, ...)
  • Update Panels in random order

Your job is to implement this functionality by combinging the Observer and Strategy patterns. The algorithms for updating observers should be encapsulated following the conventions of the Strategy pattern and each time the ColorGenerator changes its color, it randomly picks one of the algorithms, and then delegates notification of the observers to that algorithm.

This assignment is due Thursday, October 29th, at 11:55 PM. Provide a link to a single zip file containing your code and a README file describing your solution and how to run it.

Note: As with previous assignments, you may use any OO programming language that you want. Just be sure that your assignment follows the requirements above. If you build a GUI-based solution to this problem that can't run on a platform used by the grader or that requires installing third-party libraries on top of a default installation of a particular language (such as Python), the grader may contact you to set up a meeting to see your code in action.

Also Note: You are expected to follow the conventions of the Observer and Strategy patterns in your implementation. A solution that provides the stated functionality but is not structured according to these patterns will not receive a passing grade.

As with previous homeworks, you may work on this assignment in teams.

Any questions? Send them to Prof. Anderson

To achieve this grade: Rubric
A A graphical implementation of the program (using Java Swing, wxPython, .Net, etc.) is submitted. The code adheres to the structure of the two patterns and meets all of the requirements specified above. Clear attention to detail is evident in the work and the code is well structured and documented.
B A command line/text-based version of the program is submitted. All requirements are met but with less polish and/or the structure of the patterns is not followed comprehensively.
C All requirements are met but with low polish or with major problems with respect to code quality and/or adhering to the struture of the patterns.
D The assignment was of low quality with poorly structured and/or non-functional code. The design patterns were only tangentially used in the implementation or were implemented incorrectly.
F The assignment was either not submitted or was of extremely poor quality. Poor quality work would consist of missing most of the requested functionality and ignoring the use of the requested design patterns in the submitted program.
© Kenneth M. Anderson, 2009.