SUNY Geneseo Department of Computer Science
Introduction
to Design
{Date}
CSci 141, Fall 2004
Prof. Doug Baldwin
Return
to List of Lectures
Previous Lecture
Questions?
Lab deliberately graduated series of exercises
- Expect everyone to do 1
- No-one to do 4
Reading Summary
Sections 2.1 - 2.3, 2.5
Abstraction (concentrating on some essential
features while ignoring inessential ones) as a
tool for thinking about algorithms
- Object-oriented programming (dividing an
algorithm's work between software agents --
objects -- that each solve part of the problem) is
a mechanism for using abstraction in modern
computer science
- Objects abstract what an object can do
(messages it handles) away from how it does
those things (methods)
Pre- and postconditions provide an abstract
interface to an algorithm: they specify what the
algorithm needs in order to work (preconditions)
and what it produces in return (postconditions)
Objects can also abstract values/data, as well
as actions.
Some comments on this reading summary
- I consciously fit it into the 5 sentences guideline.
But short doesn't mean easy -- it took a fair bit
of thought (and understanding) to figure out what
the 5 most important ideas were and how to state
them
- Not just an outline of the text -- lots that was in
the text (especially examples) never got
mentioned, what did get mentioned was
paraphrased to some extent
- I wrote it down -- not required of you, but a good
exercise when you need to clearly but concisely
lay out the essence of a bunch of complicated
ideas
- This summary didn't illustrate the possibility of
asking questions in a reading summary, but
remember that identifying and asking a small
number of key questions is just as legitimate as
summarizing like I did above
Mini-Chess
An example of object oriented ideas
Chess, but on a small board and with only 4 pieces
per side:
Try a game
What does this have to do with object oriented
programming?
- Pieces moving...
- Classes & subclasses
- King
- Queen ... subclassses of ... Piece
- Knight
- "Piece" is a class because all pieces
respond to "move" -- interface
- "King", etc are subclasses because they
handle "move" differently -- implement
- People were objects
- "Move to square x and take piece y"
- Is a message with parameter x
- (possibly also parameter y)
- Has precondition that y is opposite
color from x
- Plus preconditions based on movement
rules and varying according to class
- Methods were (barely conscious) processes
people used to move from place to place
- Color could be a member variable
- aka "attribute", "property",
"instance variable"
- Or encoded in class
Cell Phones and Abstraction
Two descriptions of how to place a call:
- Push buttons for the number to call, then push
another button to place it
- Push buttons for the number to call, which
generates "interrupts" to the computer in the
phone, which stores the number somewhere in its
memory; when the "interrupt" for the "dial" button arrives
the computer causes the radio transmitter to emit radio waves that vary subtly
in their timing....
The first of these is much more useful to someone
wanting to make a call, because it is more
abstract -- it hides or filters out many details
of how a call is "really" placed in order to
emphasize just what a person using the phone
needs to know.
Next
Introduction to Theory
Read Sections 3.1, 3.2, 3.6
Next Lecture