Principled approach to teaching OO first - PowerPoint PPT Presentation

About This Presentation
Title:

Principled approach to teaching OO first

Description:

1. Maintain rhinos. Storyline on endangered species. ... 2. Maintain rhinos. extension of 1 to include a static variable (number of Rhinos created) and more ... – PowerPoint PPT presentation

Number of Views:21
Avg rating:3.0/5.0

less

Transcript and Presenter's Notes

Title: Principled approach to teaching OO first


1
Principled approach to teaching OO first
  • David Gries
  • Computer Science, Cornell

1
2
(No Transcript)
3
3. Present concepts at the appropriate level of
abstraction
The computer itself is not the right level of
abstraction for beginners. Give them a model they
can understand without mentioning the computer
and its memory.
The computer must always know the type of value
to be stored in the memory location associated
with a variable. An object reference variable
actually stores the address where the object is
stored in memory. An object has its own unique
identity, which distinguishes it from all other
objects in the computers memory . An objects
identity is handled behind the scenes by the Java
virtual machine and should not be confused with
the variables that might refer to that object.
(1) gives impression that only computers can
execute programs. (2) confuses people who have
little idea of memory, virtual machines, and how
computers work.
3
4
3. Present concepts at the appropriate level of
abstraction
Algol 60 language definition does not mention the
computer.
The purpose of the algorithmic language is to
describe computational processes. A variable
is a designation given to a single
value. Assignment statements serve for assigning
the value of an expression to a variable . The
process will be understood to take place in
three steps as follows 4.2.3.1. Any subscript
expressions occurring in the left part variable
are evaluated in sequence from left to
right. 4.2.3.2. The expression of the statement
is evaluated. 4.2.3.3. The value of the
expression is assigned to the left part variable,
with any subscript expressions having values as
evaluated in step 4.2.3.1.
4
5
3. Present concepts at the appropriate level of
abstraction
The computer itself is not the right level of
abstraction for beginners. Give them a model that
they can understand without mentioning the
computer and its memory.
Problem students dont know how to execute the
assignment statement.
Variable 1. A name associated with a
value. 2. A named box with a value inside it.
To execute the assignment (1) evaluate the
expression and (2) store its value in the
variable.
5
6
4. Order material to minimize the introduction
of terms or topics without explanation
When using Java, this principle almost requires
teaching OO first
Requires an IDE that removes the need for a
method main or an applet DrJava BlueJ I
dont mention method main or applets until week
11, and then I can do both on the same day.
6
7
5. Use unambiguous, clear, precise terminology
Formal parameter actual parameter
Pointer-reference
y x
Expression x evaluates to a1
7
8
(No Transcript)
9
(No Transcript)
10
Objects of a subclass
public class Demo

extends JFrame
private int w
/ area of window / public int area()
return getWidth() getHeight()
a1
bottom-up ruleSearch for a component from the
bottom up gives the overriding method
area() return getWidth()getHeight()
10
11
The inside-out rule for determining which
component is referenced

Demo
area() return getWidth()getHeight()


file drawer for class Demo
Look in the current construct, its surrounding
construct, its surrounding construct, etc., until
a matching component is found.
11
12
Contents of first lectures
Two lectures per week, with a closed, mandatory
lab between them
01. Expressions, variables, assignment Lab
practice types int, double, boolean, string
casting assignment 02.
Objects (students see JFrame objects) 03. The
class and subclass definitions (simple
function/proc decs with return statements and
method calls Lab write simple function/proc
declarations in a subclass of JFrame 04. Fields,
getter/setter methods, simple constructors 05.
Static components, the class hierarchy, JUnit
testing Lab use JUnit test cases to find and fix
errors in a given program practice with
static components 06. How a method call is
executed. if- and if-else statements. local
variables.
12
13
Contents of first lectures
Two lectures per week, with a closed, mandatory
lab between them
07. Inside-out rule super-this stepwise
refinement Lab practice write functions (if-
and if-else no loops!)
08. Constructors in subclasses stepwise
refinement 09. Wrapper classes stepwise
refinement Lab Learn about class Vector 10.
Recursion 11. Recursion Lab Writing recursive
functions 12. Casting among class-types operator
instanceof function equals.
13
14
Assignments
1. Maintain rhinos. Storyline on endangered
species. fields, setter/getter methods,
boolean expressions, JUnit testing.
/ true if r not null and this rhino is older
than r false otherwise / public boolean
isOlder(Rhino r) return r ! null
(year lt r.year (year r.year
month lt r.month))
3. Write several functions using assignment, if,
if-else. JUnit testing A. Translate between rgb,
cmyk, hsv color models B. TimeZone an instance
maintains a time in one of 12 time zones C.
Maintain dates in various forms and translate
between them D. Bowling an instance maintains a
bowling frame. The calculation of the score in
the frame requires thinking.
2. Maintain rhinos. extension of 1 to include a
static variable (number of Rhinos created) and
more comparison methods.
14
15
(No Transcript)
16
A principled approach to teaching programming
Using Java, OO comes first
Allows OO stuff to be used (and understood!!!)
throughout the course
Stress good programming practices good
specifications, class invariants, stepwise
refinement, integrated testing using JUnit
First assignment requires mastery, everyone
gets 100/100 Allows students to learn from
their mistakes, without penalty
Interesting, inspiring assignments generate
enthusiasm
Cornell I teach 130 to 160 students each
semester. At least 50 have not programmed
before. Mainly engineering, but from all other
disciplines, too
16
Write a Comment
User Comments (0)
About PowerShow.com