Hand in: email your solution (as a plain text file) to barak+cs351@cs.nuim.ie

Due: 09:00 on Wed 28-Nov-2007.

Teamwork is encouraged. Please work in teams of up to three (3) people. The teams for this assignment must be disjoint from the teams of previous assignments. (This means that no two people who were previously on the same team can be on the same team.) Just turn in one (1) solution set, with the entire team listed at the top, sorted by how much each person contributed. (The order will not affect grades; it will be used only for my own consistency checking of scores at the end of the course.)

NUIM/CS351 Assignment 4

Object-Oriented Computing via Closures and Delegation/Prototypes

The objective of this assignment is to implement an object hierarchy using closures.

  • Use delegation and prototypes to define a hierarchy of animals, including Fido and Fifi (male and female dogs); Dumbo and his mother Gertrude (elephants, but Dumbo is atypical in that he's small and flies); Kermit the frog; Mrs-Piggy, a pig; Tony the toad; Siddhartha the Snake; Fiona the chimpanzee; and Barak the human.

    You should include a generic animal object, amphibian object, mammal object, reptile object, primate object, and an object for each particular species. All the final animal objects should respond to each of the following messages:

    has-thumbs?, biped?, slimy?, hairy?, eye-count, enormous?, sound, sex, flies?, lays-eggs?.

    Put all methods as high up the hierarchy as possible, overriding them as necessary.


    (send dumbo 'flies?)                   ; #t
    (send barak 'flies?)                   ; #f
    (send barak 'eye-count)                ; 2
    (send kermit 'has-thumbs?)             ; #f
    (send fiona 'lays-eggs?)               ; #f
    (send kermit 'lays-eggs?)              ; #t
    (send fifi 'enormous?)                 ; #f
    (send gertrude 'enormous?)             ; #t
    (send mrs-piggy 'sex)                  ; female