SUNY Geneseo Department of Computer Science
Object
Oriented Programming Concepts
{Date}
CSci 141, Spring 2004
Prof. Doug Baldwin
Return
to List of Lectures
Previous Lecture
Misc
Missing appendix for book
Course e-mail list has a different name:
- csci141-spr04-l@geneseo.edu
Questions?
If "method" is executed by an object, what
about "main"?
- "Static" methods aren't associated with
objects
- Executed by "the computer"
Reading Summary
Chapter 2
Program, implementor and client
- Client: gives preconditions
- Implementor: works with preconditions to
establish postconditions
Robot example -- e/g., drawing squares
Abstraction
Algorithms that are series of steps
Classes, methods, messages
- How to use messages in algorithms
Algorithms produce either side-effects or values
Abstraction also allows hiding values (member
variables) as well as actions
An Example Abstraction
Cell phones
Software is very complicated
- Developers need to think abstractly
- Think about details of some parts while
ignoring details of other parts
Another example:
"for all real numbers, x, x+1 > x"
- "x" is abstraction
- Mathematics is probably our best-developed
abstract system
Mini-Chess
An example object oriented system
Play a game
What object oriented concepts did you notice in
this game?
- Abstraction, e.g., in directions to pieces
(aka messages)
- Objects (16 pieces, board)
- Classes (pawn, king, knight, etc)
- Subclasses (pawn, king, etc. are variations
on "chess piece")
- Maybe also black pawn vs red pawn
- Or could think of color as "state", also
position, captured or not
- Often represented in member variables
- "Checkmate" as a piece of board's state?
- Method -- Algorithm (what pieces did)
- Messages (commands from players)
- Parameters (information about where to move)
- Objects have names
- Side effects (pieces changed position,
leaving game)
- Preconditions (no move can put own king in
check)
- Postconditions (pieces having new positions,
pieces have been captured)
Next
Theory
Read 3.1 - 3.3, 3.5, 3.6
Next Lecture