Introduction to �Object Oriented Programming�
Gayathri Namasivayam
Introduction to OOP
Topics
Introduction to OOP
Topics
Introduction to OOP
Why use OOP?
Introduction to OOP
Topics
Introduction to OOP
Building Blocks of OOP: Objects & Classes
Introduction to OOP
Building Blocks of OOP: Objects & Classes
Introduction to OOP
Real World Example of Objects & Classes
Introduction to OOP
Object: FordCar1
Behavior
Start, Accelerate, Reverse, Stop
Attributes
Color: Yellow
Type: Coupe
Model: Mustang
Cylinder: 6
Attributes
Color, Type, Model, Cylinder
Behavior
Start, Accelerate, Reverse, Stop
Class: FordCar
Behavior
Start, Accelerate, Reverse, Stop
Attributes
Color: Orange
Type: Coupe
Model: Focus
Cylinder: 4
Object: FordCar2
Another Real World Example..
Introduction to OOP
Attributes
Name, Height, Age
Behavior
Speak, Listen, Eat, Run, Walk
Class: Person
Object: Person1
Attributes
Name: Ann
Height: 5’ 4”
Age: 21
Behavior
Speak, Listen, Eat, Run, Walk
Attributes
Name: Adam
Height: 5’ 9”
Age: 24
Behavior
Speak, Listen, Eat, Run, Walk
Object: Person2
Class
Introduction to OOP
Class ShippingBox
Introduction to OOP
int shipping_cost() {
return cost_per_pound*weight;
}
sender_name : string
receiver_name : string
cost_per_pound : int
weight : int
shipping_cost() : int
Object
Introduction to OOP
Objects of ShippingBox class
Introduction to OOP
sender_name = Jim
receiver_name = John
cost_per_pound = 5
weight = 10
shipping_cost()
Object BoxB
Object BoxA
sender_name = Julie
receiver_name = Jill
cost_per_pound = 2
weight = 5
shipping_cost()
Class ShippingBox
Topics
Introduction to OOP
What is OOP?
(1) Ann walks to her car
(2) Ann sends a message to the car to start by turning on the ignition
(3)The car starts
Introduction to OOP
Problem Solving in OOP
Problem: Ann wants to start her car
Introduction to OOP
Name = Ann
Age = 21
Speak()
Run()
Walk()
Object Ann
Color = Yellow
Type = Coupe
Model = Mustang
Cylinder = 6
Start()
Accelerate()
Stop()
Object Ann’s car
message
Topics
Introduction to OOP
Abstraction
Introduction to OOP
Ex. In an application that computes the shipping cost of a box, we extract its properties: cost_per_pound, weight and its behavior: shipping_cost()
Abstraction
Introduction to OOP
sender_name : string
receiver_name : string
cost_per_pound : int
weight : int
shipping_cost() : int
Class
Shipping Box
Attributes
Sender’s name,
Receiver’s name,
Cost of shipping per pound,
Weight
Behavior
Calculate shipping cost
Abstraction
Topics
Introduction to OOP
Encapsulation
Introduction to OOP
sender_name
receiver_name
cost_per_pound
weight
shipping_cost()
Topics
Introduction to OOP
Inheritance
Introduction to OOP
Inheritance Example
BankAccount CheckingAccount SavingsAccount
Introduction to OOP
customer_name : string
account_type : string
balance : int
insufficient_funds_fee : int
deposit() : int
withdrawal() : int
process_deposit() : int
customer_name : string
account_type : string
balance : int
deposit() : int
withdrawal() : int
customer_name : string
account_type : string
balance : int
interest_rate : int
deposit() : int
withdrawal() : int
calculate_interest() : int
Inheritance Example
Introduction to OOP
interest_rate : int
calculate_interest() : int
insufficient_funds_fee : int
process_deposit() : int
CheckingAccount
SavingsAccount
customer_name : string
account_type : string
balance : int
deposit() : int
withdrawal() : int
BankAccount
Topics
(* To be covered in the next class)
Introduction to OOP
Disadvantages of OOP
Introduction to OOP
Conclusion
Introduction to OOP
Thank you!
Introduction to OOP