CSC 216 F09/Polymorphism: Difference between revisions
No edit summary |
No edit summary |
||
Line 30: | Line 30: | ||
* row 1 - Designers | * row 1 - Designers | ||
==Objective== | ====Objective==== | ||
The objective is to create the creatures within a new MMO. To begin, an Animal class has to be created, and the methods/variables of an Animal must also be created. This is the job of the entire class. The current Programming team will type/write this code to be displayed as ideas are called out. | The objective is to create the creatures within a new MMO. To begin, an Animal class has to be created, and the methods/variables of an Animal must also be created. This is the job of the entire class. The current Programming team will type/write this code to be displayed as ideas are called out. | ||
Revision as of 05:48, 17 November 2009
Formatting Resources
Formatting Help Guide from MetaWiki
Create a Creature
The problem
Students will learn the principles of inheritance and polymorphism.
Participants and props
This game requires a minimum of three people, but is designed to engage an entire class. A driver created in Flash can be used, but is not required.
The script
The class will be divided up into teams (by row, programming partners, etc.). The first team will be the "Artists," the second team will be the "Programmers," and all of the remaining teams will be the "Designers." Turns cycle from Designer -> Programmer -> Artist
For example: If we divided the class into teams by row and there were 5 rows:
- row 1 - Artists
- row 2 - Programmers
- row 3 - Designers
- row 4 - Designers
- row 5 - Designers
After the first rotation, the roles would be:
- row 2 - Artists
- row 3 - Programmers
- row 4 - Designers
- row 5 - Designers
- row 1 - Designers
Objective
The objective is to create the creatures within a new MMO. To begin, an Animal class has to be created, and the methods/variables of an Animal must also be created. This is the job of the entire class. The current Programming team will type/write this code to be displayed as ideas are called out.
Example:
abstract public class Animal {
private boolean living; public void eat(); public Animal() { this.living = true; } public void die() { this.living = false; }
}
Now we need to make a subclass that extends Animal.
//name the creature public class ____ extends Animal {
//add unique characteristics public ____(){ super(); } public eat(){ //define herbivore, carnivore, omnivore status } //add other methods : attack, walk, fly, etc.
}
As each method is written, the artists must draw a creature that implements those methods. For example, if the hear method requires the creature to attack using a unicorn horn, the artists will add a unicorn horn to the creature. The designers call out ideas and critique the written code and drawn animals. It is the designer's job to come up with the components of the creature and what it can do. The programmer's must translate this into code.
The roles rotate after a method has been completed. When the creature is complete, the designers decide if a subclass of this class should be written (i.e. boss, weaker version etc.). The class can create as many creatures as desired, but for the sake of time, 2-3 creatures would complete the lesson.
Questions
After the activity is completed, the instructor should ask the following questions: 1. Can a (created creature's name) be a (other creature name)? If so, what methods would we have to modify? 2. Can an Animal be casted as a ___? Can a _______ be casted as an Animal?