Prototype Pattern Lab

Lab: Enhancing the Game Character Application

Objective:

In this lab, you will extend the provided Game Character application. The existing application includes GameCharacter as the prototype, Warrior and Mage as concrete prototypes, and a CharacterStore to store and clone these characters. You will add a new game character called "Archer" to the existing system.

Instructions:

  1. Start by examining the existing GameCharacter, Warrior, Mage, and CharacterStore classes to understand how the Prototype design pattern is implemented.

  2. Create a new class called Archer that extends GameCharacter. Define the play() method for Archer to print a message indicating that the Archer is shooting arrows.

  3. In the CharacterStore class, add the Archer object to the characterMap in the loadCache() method.

  4. Update the PrototypePatternDemo class to demonstrate the use of the new Archer class. Create cloned objects of the Archer class and invoke the play() method on them.

  5. Test your application to ensure that it behaves as expected.

Bonus:

For extra credit, consider the following enhancements:

  • Add attributes such as healthPoints, attackPower, and defensePower to the GameCharacter class and their corresponding getter and setter methods. Make sure these attributes are correctly cloned in each prototype.

  • Implement different behavior for the play() method based on these attributes.

Tips:

  • Remember that the Prototype pattern is used to create a new instance of a class from an existing instance. This can be useful when object creation is a costly operation and you need multiple similar objects.

Submission:

You should submit your completed Java files for GameCharacter, Warrior, Mage, Archer, CharacterStore, and PrototypePatternDemo.


Remember, the goal of this lab is to understand the Prototype pattern and how it can be used to efficiently create new objects when object creation is expensive or complex.