CSC 216 F09/Inheritance-Polymorphism: Difference between revisions
No edit summary |
No edit summary |
||
(3 intermediate revisions by the same user not shown) | |||
Line 7: | Line 7: | ||
''An example is given:'' | ''An example is given:'' | ||
One person is designated as the Mammal class. The mammal class has a walk(), and a talk() method. | -One person is designated as the Mammal class. | ||
-The mammal class has a walk(), and a talk() method. | |||
-3 other people are designated as the subclasses: "Cow", "Person", "Duck" (or any other mammal with a distinct vocal characteristic). | |||
-The four people are given class-name tags for clarity. | |||
-Each of the classmates can then walk up to the subclasses and ask them to perform one of the inherited methods (walk() or talk()). | |||
-The subclass then performs his/her interpretation of how that mammal talks or walks. | |||
''*More Superclass/subclass relationships can be used to allow for more classmate interaction. *'' | ''*More Superclass/subclass relationships can be used to allow for more classmate interaction. *'' | ||
Line 16: | Line 24: | ||
The entire class will be able to participate in this activity. The people designated as the classes will perform the methods that are called by their classmates. | The entire class will be able to participate in this activity. The people designated as the classes will perform the methods that are called by their classmates. | ||
''By: Colin Craig and Augustine Sebera'' |
Latest revision as of 04:32, 18 November 2009
The Problem
This exercise demonstrates the effect of inheritance/polymorphism through class interactions. Several students will be designated as the Superclasses while others will be designated subclasses of that superclass. Each person designated as the superclass has a set of methods that are inherited by the subclasses. The subclasses then can perform these methods relative to the properties of their class. This exercise can provide for a humorous way to understand how classes can inherit methods from it's superclass.
An example is given:
-One person is designated as the Mammal class.
-The mammal class has a walk(), and a talk() method.
-3 other people are designated as the subclasses: "Cow", "Person", "Duck" (or any other mammal with a distinct vocal characteristic).
-The four people are given class-name tags for clarity.
-Each of the classmates can then walk up to the subclasses and ask them to perform one of the inherited methods (walk() or talk()).
-The subclass then performs his/her interpretation of how that mammal talks or walks.
*More Superclass/subclass relationships can be used to allow for more classmate interaction. *
Participants
The entire class will be able to participate in this activity. The people designated as the classes will perform the methods that are called by their classmates.
By: Colin Craig and Augustine Sebera