CSC 216 F09/polymorphism showdown

From Expertiza_Wiki
Jump to navigation Jump to search

Jim Creager, Davis Dulin, and Ian Charle

Polymorphism - Changing the Shape of Your Program

Polymorphism is the ability of a subclass to define new or share functionality with a superclass. A subclass automatically has possession of public and protected variables and methods in its superclass. These inherited variables and methods can be called directly from an object of the subclass without having to change type.

Overriding

It is also possible to redefine variables and methods within a subclass. In such a case, a variable/method defined in the subclass overrides the variable/method with the same name in the superclass. When called from an instance of the subclass, the variable/method defined in the subclass will be accessed instead of the one in the superclass.

Overloading

Overloading is a technique by which a method takes on many forms. Overloading occurs when a method name is used multiple times, but each instance of the method contains different parameters. This allows multiple variations of the same action to occur depending on circumstances.

Casting

Polymorphism also allows objects of one class to be transformed into objects of another class. This is particularly useful when changing functionality in an inheritance relationship. An instance of the superclass’ type can be set equal to an instance of the subclass’ type without any conflicts in the program. This is because the subclass is a more specific class of the superclass. Moving from subclass to superclass, however, would be making the subclass more generic. A technique known as casting is required to perform this change. Casting objects is only valid when moving in a upward along an object’s hierarchy (up to the superclass). Casting cannot be used between objects on the same level of the object hierarchy, and casting is not necessary to move down the object hierarchy. By placing a superclass’ name in parentheses just before the object you want to transform, you are declaring a new type, or casting.

Polymorphism Showdown - The Game

Polymorphism Showdown is a quiz-based game that tests knowledge of polymorphism concepts with relation to inheritance. The goal is to familiarize participants with casting, overloading, and overriding. Questions use a variety of formats, including UML diagrams and code snippets, to acclimate participants to conceptual application and direct code application. Participants are required to think on their feet and answer quickly so that an active audience is maintained and learning continues.

Participants and Props

Required: PowerPoint slideshow of quiz questions, GoogleDocs answer form, corresponding GoogleDocs spreadsheet, and a chalkboard/whiteboard for score keeping.

The entire class participates in this exercise. Students attempt quiz problems as individuals while earning points for their team. Rows compete against each other to earn the highest score.

How It Works

There will be two types of questions in the game: free-for-all and showdown. Numbered questions indicate a free-for-all type in which all students participate. Numbered questions followed by an ‘S’ indicate a showdown type in which select students participate. All students attempt to correctly answer free-for-all problems as fast as possible. The first student from each row to answer correctly advances to the showdown round as a representative for his/her row. The first student to correctly answer the showdown problem receives a point for his/her row.

Steps To 30 Minute Completion

Free-for-all questions take about 30 seconds to answer. Allot say 30 (more than necessary) seconds to one-click sort the answers and announce those who advance to the showdown round. The answer slide (with explanation) is displayed for the students to read while the instructor does this. Showdown questions tend to be even faster - often based off the same premise as the free-for-all question just before. It would be appropriate to allot 20-25 seconds for students to answer these and 20 seconds for the instructor to display the answer and mark a point for the winner.

  1. The instructor should first create tally columns on the chalkboard/whiteboard for each row of students in the classroom.
  2. The instructor should then bring up the Polymorphism Showdown PowerPoint on the display. The option is given on the home slide to review polymorphism concepts, review game instructions, or skip straight to the questions.
  3. When ready to begin the game, a link to the GoogleDocs answer form will need to be provided to the students. At this time, the instructor should pull up the form’s corresponding spreadsheet on another computer or a second window.
  4. To begin the exercise, every student should fill in the next question number, his/her initials, and his/her row number on the GoogleDoc answer form. The answer text field should be left blank, and the form should NOT yet be submitted.
  5. The instructor should then count down and flip the PowerPoint to the slide containing the next question.
  6. Students are to answer and submit the form as fast as possible. Each student should only submit once.
  7. After 30 seconds to 1 minute, the instructor should prevent the spreadsheet from accepting submissions. The PowerPoint can then be changed to the next slide which contains the answer.
  8. The instructor should then sort data in the spreadsheet by right clicking the “Row Number” column and selecting “From A-Z.” This will organize answers into groups of row 1, row 2, etc., and answers within each group will be in order of time submitted (earliest first).
  9. The first person from each row to submit the correct answer (identified by initials) is then designated to participate in the next question, a showdown between rows.
  10. After designating the representatives for each row, the instructor should clear the data cells of the spreadsheet. Submissions should be permitted once again. This allows the same form and spreadsheet to be reused.
  11. Row representatives then revisit the GoogleDocs form and fill out entries as before, this time selecting the appropriate showdown question number.
  12. The instructor counts down and the PowerPoint is flipped to the next slide which contains the showdown question.
  13. Students are to answer and submit as fast as possible.
  14. Data will fill the spreadsheet in order of time submitted. When the first correct answer arrives, the instructor should announce that there is a winner and stop further submissions from being received.
  15. The instructor then adds a tally to the chalkboard/whiteboard for the row that the winner represents.
  16. The instructor should clear the data cells of the spreadsheet. Submissions should be permitted once again.
  17. Steps 4-16 are repeated for remaining questions.