From last time…
•

We discussed Iteration 1 expectations!

•

Functions:!

! - DRY: Don’t Repeat Yourself!
! - How to “read” a function definition!
! - Type & number of arguments must match!
! - Arguments are passed by copy into functions!
•

Reviewed Quiz 2: Variables, Conditionals, Loops
“All programming languages !
are exactly the same.”

Prof. Angelos Barmpoutis!
University of Florida
Programming Languages

vs. Natural Languages

Variables, Operations,
Logical Operators

Sounds, Words

Functions

Sentences

Conditional Statements

Paragraphs

Objects

Chapters, Entire Books
Objects I

CAP
Object-Oriented
Programming
•

OOP is a programming paradigm!

•

It a mental model for thinking about code!

•

It informs the organization & structure of code!

•

Object-oriented code is organized into “objects”
that interact with each other
c++
c#
smalltalk
ruby

php

java

objective-c

python

perl
What do we know so far…
Data!
variables – store data: int, boolean, float, etc.!
operations – manipulate data: + - / *!
logical operators – compare data: > < >= <= ==!

Functionality!
functions – simple behavior: size(), fill()
loops – repeated behavior: for (int i = 0; i < 100; i++)!
conditionals – flow control: if (conditional) {} else {}
Objects
•

It makes sense to organize related
data and functionality into one thing!

•

We call this thing an ‘object’!

•

Any thing in the world could be viewed as an
object—as a grouping of data and functionality
Object-Oriented Thinking
•

An Animal!

•

A Human!

•

A Vehicle!

•

A Celestial Body… and Gravity!

•

An Email… An Inbox… and An Email Application!

•

In programming, objects are defined by classes
Class Anatomy
Name

Class!
Blueprint!
Cookie Cutter!
Mould

Data

What is the class called?

What are its attributes?!
What state is currently it in?

Constructor

When I create a new one,!
what do I need to do?

Functionality

What actions can it take?!
What does it do?
Class Anatomy
Name

Class!
Blueprint!
Cookie Cutter!
Mould

Data
Constructor
Functionality

Vehicle

String type; // e.g.,“Car”
float price; // e.g., 7825

Vehicle(type, price)

moveForward();
moveBackward();
honk();

Notice that a class is a generic blueprint–a container.!
It has placeholders for data, and defines functionality.
Classes make Objects
Class! Object! Object! Object!
Vehicle!

Vehicle!

Vehicle!

Vehicle!

!
!

!

!

!

String type!
float price

“Car”!
2374.72

“Car”!
4255.95

“Airplane”!
400000

These are instances of the Vehicle Class
Demo!
A Star Class
Remember…
A class must have 4 things:!
1. a name!
2. attributes (variables)!
3. a constructor (run once, when we use new)!
4. methods (functions)!
Learn and memorize how to make code into classes!
“All programming languages !
are exactly the same.”

Prof. Angelos Barmpoutis!
University of Florida
Unified Modeling Language
UML defines a consistent method for diagramming
a class. This is what a “Class Diagram” looks like:
Name!
!
Variables!
!
!
Methods
Class Diagram Example
Email

Inbox

MailManager

to
from
subject
body

name
emails

inboxes

displayEmail
orderEmailsByAlpha
orderEmailsByDate

displayInbox
createEmail
sendEmail
checkEmail
For next time…
•

Read Shiffman, p. 130–137 (Objects II)!

•

Keep working on Iteration 1

12. Objects I