SE-2811 Software Component Design
Lab 2: Creating Strategies with Factory Methods

The objective of this lab is to refactor the Angry Bees simulation such that both the Game and GameCharacter classes encapsulates behaviors the Strategy Pattern, and incorporate the Factory Method pattern into the Bee and Flower classes to create those characters.

Assignment

Download the TagBehavior.java and MoveBehavior.java files containing the interfaces that define the MoveBehavior and TagBehavior strategies. Since these are just interfaces, you'll have to provide the implementation of the concrete strategies in concrete classes. You will need to create 4 classes that implement the MoveBehavior interface; these are

You will need to implement 2 classes that implement the TagBehavior interface; these are:

The class diagram representing this application's structure after the is as follows (the different colors serve only to differentiate strategy interfaces from strategy implementations):

To create Bees in this version of the game, note that you must modify the Bee class to implement a Factory Method named createBee(), which handles the creation of the Bee itself as well as a specified behavior (supplied to createBee() as an enum). Similarly, to create Flowers, you must modify the Flower class to implement a createFlower() Factory Method.

In the Game class, you must modify Game to implement the TagBehavior interface, create an instance of StandardTagBehavior in the main() method, and set the tagBehavior attribute to initially reference that instance. The Game.tag() method thus initially uses StandardTagBehavior whenever that method is called from a GameCharacter's finishMove() method. You must modify the Game class's runGame() method to switch to use AdvancedTagBehavior when the remaining time is 80% of the original game time. No special Factory Method is needed to create or switch these behaviors.

Lab Submission (due 8:00am Monday 3/19/2012 via SVN)

Your assignment will consist of:

Submit your assignment by committing your projects entire source folder to your SVN repository in a top-level project named "Lab2" (no trunk, branches, or tag is needed). The .pdf image file should be directly in the Lab2 folder, but all code should be in a subfolder of Lab2 named "src". Do not commit any binary files (such as .class files), and do not commit the EA project file.