Documentation for the define-class.ss package
Download the define-class package (not required for lab, but useful for working at home).
At the top of your definitions window, type the following line to load the define-class.ss package:
(load "/home/comp210/Lectures/define-class.ss")
Write the class Animal% with the following
Normally, the Animal% class would be considered abstract, and hence one would not be able to make and instance of it, but this Scheme implementation of won't stop you, so we'll take advantage of that here.
Create an "instance" of ("instantiate") Animal% :
(define animal (make-object Animal% "anAnimal" "no sound"))
Test that the animal does what it is supposed to do:
(send animal getname)
(send animal get-sound)
(send animal speak)
Create the class Dog% where:
Test your Dog class by creating an instance of one and testing ALL of its methods.
Create a Cat% class similarly to Dog, but whose speak method is different than Dog%
Now, write a function that takes an Animal% and return a string with the animal's name and what it speaks.
Test your function on both Dog% and Cat% instances. This is a demostration of the hugely important concept of "polymorphism", which is that if two objects are abstractly equivalent, they can be used interchangeably wherever the abstract class is needed, but that they will still have their own distinct behaviors.
Modify your function so that it works on a list. Test it with a list filled with both Dogs and Cats.
Create a Bird% (or whatever) class that
Note: to add more arguments to a sub-class's constructor than the superclass has, write the following super-class initializer as the first function of the body of the class:
(super-init arg1 arg2 ....)
where the args are the arguments of the superclass constructor.
Use your imagination!