announcements introduction to object oriented programming ...ab/15-110f10/annotatednotes/lecture 23...
TRANSCRIPT
10/30/2010
1
Introduction to Object Oriented
Programming
(OOP)
Announcements� Do Salons
� Read OOP salon and respond to questions
� Lab 5 is due next Saturday
� Simple OOP assignment
Lets take a look @ Lab 4
Why do we need to read a file to
an array?
How do we read a file into an
array? How do we search an array?
10/30/2010
2
Can a function call another
function? How?
Object Oriented Programming
So far we thought of programs as
step by step instructions provided
to a computer to solve a problem
We broke the program into
________ so that we can
modularize the code and reuse the
code in different ways
Approach was good for
- printing custom tickets
- calculating monthly cable bill
- Writing a simple spell checker
- etc…
However, programmers also write
programs to manipulate physical
objects
10/30/2010
3
Physical Objects All objects belongs to Classes
Class of Robots Class of Cars
A Class is defined as a Template for
Objects An Object is an instance of a class
Objects have behaviors
Walk
Talk
Turn
Run
Behaviors are implemented by
method or functions
10/30/2010
4
Objects have State
Color
Shape
Name
Fastest speed
State of an object is represented by
variables and constants
To program real objects we need to
understand object oriented
programming
A Java program can be embedded
into a physical object to define
behaviors
Objects communicates with each
other with messagesI need a
car
You can’t drive a car
Object communication happens
through methods/functions
Some functions are public and
some are private
10/30/2010
5
We Learn how to think about,
design and write object oriented
programs
Lets say we were asked to develop
an elevator control system
Identify objects
I love elevators
Behaviors
Elevators
Must go up and down
Must pick up
passengers
open/close doors
Passengers
Call elevatorsPick floorsClose doorOpen door
State variables
Elevators PassengersClass work
Develop Java Classes to simulate a
simple robot