41S-Section-Solution

41S-Section-Solution - CS107 Spring 2007 Handout 41S June...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
CS107 Handout 41S Spring 2007 June 1, 2007 Section Solution: Java Inheritance Solution 1: Stanford Instructors This problem is particularly suitable because it involves a set of classes that are similar to each other in most respects but differ in a few crucial aspects of their behavior. Below is the sort of design drawing you might make to help think about your solution: Instructor Grad Lecturer Faculty Instance variables: •unreadMail •age •eccentricities Class variables: •MAX_STRESS Methods: -getStress() -getRespect() -checkMail(int) Methods: -getStress() -cope() Methods: -cope() Methods: -getRespect() -cope() Class variables: •static numFaculty Inheritance diagrams such as the one above are the bread-and-butter of object-oriented design. The class at the top has a list of all its methods and variables. The three classes below it are subclasses of the Instructor class, as indicated by the connecting lines. By convention, the class on the top is the superclass (i.e., the base class) and the one below is the subclass (the specialized class). Note that the three subclasses each only lists a few methods and variables. By default, we assume that each subclass has exactly the same methods and variables as its superclass, and only explicitly indicate methods and variables when they are exclusive to the subclass. These diagrams are useful because they clearly indicate the code sharing within a class hierarchy without the clutter and hassle of actual code. All common data have been factored up to the Instructor superclass, and each subclass is only listed with the methods and variables that are specific to that class. As a rule, your code should match your
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 01/14/2010 for the course CS 107 taught by Professor Cain,g during the Spring '08 term at Stanford.

Page1 / 5

41S-Section-Solution - CS107 Spring 2007 Handout 41S June...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online