University of Virginia, Department of Computer Science
CS201J: Engineering Software, Fall 2003

Notes: Thursday 9 October 2003
Schedule

Exam 1
Exam 1 will now be handed out on October 16 and due on October 21. It will cover everything in the course before today's lecture including Problem Sets 1-4, Lectures 1-10 and assigned readings. The exam is take home and open book, but you will not be permitted to use other humans or a Java compiler for the exam (unless you write your own).

You should not be surprised if the exam contains questions about specifying procedures, data abstraction, specifying data abstractions, implementing data abstractions (including choosing good representations, rep invariants and abstraction functions), static analysis, testing, design and Java semantics. You may need to write some code snippets to answer exam questions.

The recommended ways to study for the exam are:

  1. Go over last year's exam (handed out today). You can find comments on the exam at http://www.cs.virginia.edu/evans/cs201j-fall2002/exams/exam1-comments.html but you are advised to work on the problems yourself before consulting those solutions.
  2. Go over the problem sets and make sure you understand the comments.
  3. Look over the notes and answer the questions on the notes.
  4. Practice designing and implementing data abstractions (as you are doing for PS4)
  5. Re-read sections from the book
Friday's section will be an exam review.
Notes
Subtyping
B is a subtype of A means wherever an object of type A isexpected, we can use an object of type B instead.
Object is the ultimate supertype of every object type in Java.

Inheritance
Reuse the implementation of the supertype to implement a subtype.

class B extends A means:

class C implements I means: Should a type be permitted to have more than one subtype?




Should a type be permitted to have more than one supertype?




Should a class be permitted to inherit from more than one class?




public class ExtremeLifeCell extends Cell {
   public CellState getNextState () 
       // EFFECTS: Returns the next state for this cell. 
       //    The next state will be alive if this cell or any of its neighbors 
       //     is currently alive. 
   { 
      if (countAliveNeighbors () > 0) { 
          return CellState.createAlive (); 
      } else { 
          return getState (); 
     } 
   } 
} 
ExtremeLifeCell is a subtype of Cell. Anywhere the code expects a Cell object, we can use an ExtremeLifeCell also. For example,
   public class Grid {
     /*@non_null@*/ Cell [][] cells;
the elements of the cells array in Grid can be ExtremeLifeCell objects.

The ExtremeLifeCell overrides the getNextState method and inherits the rest of the Cell implementation including its rep (note that we don't need any state to represent an ExtremeLifeCell) and the countAliveNeighbors and getState methods.

Apparent and Actual Types

Apparent types are associated with declarations: they never change
Actual types are associated with object: they are always a subtype of the apparent type

Compiler does type checking using apparent type.
Virtual Machine does method dispatch using actual type.

Can the apparent type of an array element ever change?




How can you change the actual type of a variable?




CS201J University of Virginia
Department of Computer Science
CS 201J: Engineering Software
Sponsored by the
National Science Foundation
cs201j-staff@cs.virginia.edu