Homework 5

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 worth up to four extra credit points. Two points can be earned by creating a high quality text-based solution to this problem. An additional two points are available for creating a GUI-based solution to this problem that shows the various notification strategies graphically. Most students will receive only one or two points; only the highest quality answers will receive three to four points. This assignment is due Thursday, November 6th, at 11:55 PM. Upload a single zip file to the moodle by that date 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 Mac (which is the platform used by our 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 run.


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 receive zero points.


Any questions? Send them to Prof. Anderson


Recall that you must not work with other students on this assignment. To remind you of this, please include the following pledge at the top of your README file: "On my honor as a University of Colorado at Boulder student, I have neither given nor received unauthorized assistance on this work."

Kenneth M. Anderson, 2008