CSC 216 F09/PolymorphismOfBob

From Expertiza_Wiki
Jump to navigation Jump to search

Polymorphism

Polymorphism is the use of having a subclass have its own unique behaviors and share some of the abilities of the parent class. Sometimes it refers to an object of one class, sometimes to an object of another class.

Is-A Rule

The is-a rule is a rule that helps determine if a class should be a subclass of another class.

  • ex. A car is-a drivable, and so it should be able to do anything a drivable can do.

Problem

In this exercise, we want to teach students the how polymorphism works.

Participants and Props

Participants

Props

  • A list of the following questions:
    • Are you an Object?
    • Are you an Animal?
    • Are you a Mammal?
    • Are you a Human?
    • Are you an Engineer?
    • Are you a Railroad Engineer?
    • Are you Bob?
  • 7[1] slips of paper, with the following written on them:
    • Animal
    • Mammal
    • Human
    • Engineer
    • Railroad Engineer
    • Bob, the Railroad Engineer
    • Steve, the Railroad Engineer

The Script

Setup

1. Randomly hand all but one of the participants one of the slips of paper.

2. Each person should read and memorize who they are and keep it to themselves.

3. The last participant should take the list of questions.

Activity

1. The questioner should pick one of the participants, and ask him or her the questions on the list in order, until a question is answered 'no'.

2. Based on the answers given, the group should determine what is known about the participant.

  • ex. If the participant answers no to Human, then they know that it is a Mammal, and everything above Mammal, but could be either a non-human Mammal, or a generic Mammal.

3. The participant should then reveal what they actually were.

4. Repeat steps 1, 2, and 3 for the rest of the participants.

Notes

1) If so desired, any or all of the following participants can be added:

  • A type of Object that isn't an Animal
  • A type of Animal that isn't a Mammal
  • A type of Mammal that isn't a Human
  • A type of Human that isn't an Engineer
  • A type of Engineer that isn't a Railroad Engineer