SlideShare a Scribd company logo
Introduction to
Object Oriented Programming
Gayathri Namasivayam
Introduction to OOP
Topics
●Why use OOP?
●Building blocks of OOP
● Classes
● Objects
●What is OOP?
●OOP concepts
● Abstraction
● Encapsulation
● Inheritance
● Polymorphism
●Advantages vs Disadvantages
●Conclusion
Introduction to OOP
Topics
●Why use OOP?
●Building blocks of OOP
● Classes
● Objects
●What is OOP?
●OOP concepts
● Abstraction
● Encapsulation
● Inheritance
● Polymorphism
●Advantages vs Disadvantages
●Conclusion
Introduction to OOP
Why use OOP?
●Object Oriented Programming (OOP) is one of the most
widely used programming paradigm
●Why is it extensively used?
● Well suited for building trivial and complex applications
● Allows re-use of code thereby increasing productivity
● New features can be easily built into the existing code
● Reduced production cost and maintenance cost
●Common programming languages used for OOP include
C++, Java, and C#
Introduction to OOP
Topics
●Why use OOP?
●Building blocks of OOP
● Classes
● Objects
●What is OOP?
●OOP concepts
● Abstraction
● Encapsulation
● Inheritance
● Polymorphism
●Advantages vs Disadvantages
●Conclusion
Introduction to OOP
Building Blocks of OOP: Objects &
Classes
●Object: models a
● Real world object (ex. computer, book, box)
● Concept (ex. meeting, interview)
● Process (ex. sorting a stack of papers or comparing two
computers to measure their performance)
●Class: prototype or blueprint from which objects are
created
Introduction to OOP
Building Blocks of OOP: Objects &
Classes
●Class has
● Set of attributes or properties that describes every object
● Set of behavior or actions that every object can perform
●Object has
● Set of data (value for each of its attribute)
● Set of actions that it can perform
● An identity
●Every object belongs to a class
Introduction to OOP
Real World Example of Objects &
Classes
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
Introduction to OOP
Another Real World Example..
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
Introduction to OOP
Class
●A class is a set of variables (to represent its attributes) and
functions (to describe its behavior) that act on its variables
Introduction to OOP
Class ShippingBox
int shipping_cost() {
return cost_per_pound*weight;
}
sender_name : string
receiver_name : string
cost_per_pound : int
weight : int
shipping_cost() : int
Introduction to OOP
Object
●Object is an instance of a class that holds data (values) in
its variables. Data can be accessed by its functions
Introduction to OOP
Objects of ShippingBox class
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
Introduction to OOP
Topics
●Why use OOP?
●Building blocks of OOP
● Classes
● Objects
●What is OOP?
●OOP concepts
● Abstraction
● Encapsulation
● Inheritance
● Polymorphism
●Advantages vs Disadvantages
●Conclusion
Introduction to OOP
What is OOP?
●Paradigm for problem solving by interaction among objects
●It follows a natural way of solving problems
● Ex. Ann wants to start her car
(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
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
Introduction to OOP
Topics
●Why use OOP?
●Building blocks of OOP
● Classes
● Objects
●What is OOP?
●OOP concepts
● Abstraction
● Encapsulation
● Inheritance
● Polymorphism
●Advantages vs Disadvantages
●Conclusion
Introduction to OOP
Abstraction
●Extracting essential properties and behavior of an entity
●Class represents such an abstraction and is commonly
referred to as an abstract data type
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()
Introduction to OOP
Abstraction
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
Introduction to OOP
Topics
●Why use OOP?
●Building blocks of OOP
● Classes
● Objects
●What is OOP?
●OOP concepts
● Abstraction
● Encapsulation
● Inheritance
● Polymorphism
●Advantages vs Disadvantages
●Conclusion
Introduction to OOP
Encapsulation
sender_name
receiver_name
cost_per_pound
weight
shipping_cost()
●Mechanism by which we combine data and the functions
that manipulate the data into one unit
●Objects & Classes enforce encapsulation
Introduction to OOP
Topics
●Why use OOP?
●Building blocks of OOP
● Classes
● Objects
●What is OOP?
●OOP concepts
● Abstraction
● Encapsulation
● Inheritance
● Polymorphism
●Advantages vs Disadvantages
●Conclusion
Introduction to OOP
Inheritance
●Create new classes (derived classes) from existing classes
(base classes)
●The derived class inherits the variables and functions of
the base class and adds additional ones!
●Provides the ability to re-use existing code
Introduction to OOP
Inheritance Example
BankAccount CheckingAccount SavingsAccount
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
Introduction to OOP
Inheritance Example
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
Introduction to OOP
Topics
●Why use OOP?
●Building blocks of OOP
● Classes
● Objects
●What is OOP?
●OOP concepts
● Abstraction
● Encapsulation
● Inheritance
● Polymorphism*
●Advantages vs Disadvantages
●Conclusion
(* To be covered in the next class)
Introduction to OOP
Disadvantages of OOP
●Initial extra effort needed in accurately modeling the
classes and sub-classes for a problem
●Suited for modeling certain real world problems as
opposed to some others
Introduction to OOP
Conclusion
●Classes & Objects
●Concepts in OOP
● Abstraction
● Encapsulation
● Inheritance
●Advantages & Disadvantages
●Next class
● Be prepared for an in-class activity (based on topics covered
today)!
● Polymorphism in OOP!
Introduction to OOP
Thank you!
Introduction to OOP
Ad

Recommended

Oop
Oop
志明 陳
 
oop.pptx
oop.pptx
KabitaParajuli3
 
object oriented programming and methodology.pptx
object oriented programming and methodology.pptx
ayush626953
 
object oriented programing lecture 1
object oriented programing lecture 1
Geophery sanga
 
Object-Oriented Programming (OOP)
Object-Oriented Programming (OOP)
Ahmad karawash
 
Object oriented programming 6 oop with c++
Object oriented programming 6 oop with c++
Vaibhav Khanna
 
SKILLWISE - OOPS CONCEPT
SKILLWISE - OOPS CONCEPT
Skillwise Group
 
Chapter 04 object oriented programming
Chapter 04 object oriented programming
Praveen M Jigajinni
 
Object Oriented Programming Principles
Object Oriented Programming Principles
Andrew Ferlitsch
 
L1-Introduction to OOPs concepts.pdf
L1-Introduction to OOPs concepts.pdf
BhanuJatinSingh
 
object oriented programming(PYTHON)
object oriented programming(PYTHON)
Jyoti shukla
 
Lecture 2
Lecture 2
emailharmeet
 
Object Oriented Programming Class and Objects
Object Oriented Programming Class and Objects
rubini8582
 
Procedural-vs-Object-Oriented-Programming (1).pdf
Procedural-vs-Object-Oriented-Programming (1).pdf
AnujMalviya12
 
Python programming Concepts (Functions, classes and Oops concept
Python programming Concepts (Functions, classes and Oops concept
Lipika Sharma
 
Lecture 1 oop
Lecture 1 oop
Tony Apreku
 
Regex,functions, inheritance,class, attribute,overloding
Regex,functions, inheritance,class, attribute,overloding
sangumanikesh
 
Understanding the Basics of Object-Oriented Programming for Beginners
Understanding the Basics of Object-Oriented Programming for Beginners
Emma Jacob
 
chapter - 1.ppt
chapter - 1.ppt
SakthiVinoth78
 
CPP_,module2_1.pptx
CPP_,module2_1.pptx
AbhilashTom4
 
Introduction to OOP_Python_Lecture1.pptx
Introduction to OOP_Python_Lecture1.pptx
cpics
 
Principles and advantages of oop ppt
Principles and advantages of oop ppt
daxesh chauhan
 
Oop concepts classes_objects
Oop concepts classes_objects
William Olivier
 
Object oriented programming
Object oriented programming
sana younas
 
Object Oriented Programming Concepts
Object Oriented Programming Concepts
Abhigyan Singh Yadav
 
object oriented programming(oops)
object oriented programming(oops)
HANISHTHARWANI21BCE1
 
Object Oriented Program Class 12 Computer Science
Object Oriented Program Class 12 Computer Science
ShailendraPandey96
 
slidesgo-exploring-object-oriented-features-a-guide-to-object-creation-and-pr...
slidesgo-exploring-object-oriented-features-a-guide-to-object-creation-and-pr...
valleerinavadeep
 
Pavement and its types, Application of rigid and Flexible Pavements
Pavement and its types, Application of rigid and Flexible Pavements
Sakthivel M
 
Low Power SI Class E Power Amplifier and Rf Switch for Health Care
Low Power SI Class E Power Amplifier and Rf Switch for Health Care
ieijjournal
 

More Related Content

Similar to Object Oriented Programming_combined.ppt.pdf (20)

Object Oriented Programming Principles
Object Oriented Programming Principles
Andrew Ferlitsch
 
L1-Introduction to OOPs concepts.pdf
L1-Introduction to OOPs concepts.pdf
BhanuJatinSingh
 
object oriented programming(PYTHON)
object oriented programming(PYTHON)
Jyoti shukla
 
Lecture 2
Lecture 2
emailharmeet
 
Object Oriented Programming Class and Objects
Object Oriented Programming Class and Objects
rubini8582
 
Procedural-vs-Object-Oriented-Programming (1).pdf
Procedural-vs-Object-Oriented-Programming (1).pdf
AnujMalviya12
 
Python programming Concepts (Functions, classes and Oops concept
Python programming Concepts (Functions, classes and Oops concept
Lipika Sharma
 
Lecture 1 oop
Lecture 1 oop
Tony Apreku
 
Regex,functions, inheritance,class, attribute,overloding
Regex,functions, inheritance,class, attribute,overloding
sangumanikesh
 
Understanding the Basics of Object-Oriented Programming for Beginners
Understanding the Basics of Object-Oriented Programming for Beginners
Emma Jacob
 
chapter - 1.ppt
chapter - 1.ppt
SakthiVinoth78
 
CPP_,module2_1.pptx
CPP_,module2_1.pptx
AbhilashTom4
 
Introduction to OOP_Python_Lecture1.pptx
Introduction to OOP_Python_Lecture1.pptx
cpics
 
Principles and advantages of oop ppt
Principles and advantages of oop ppt
daxesh chauhan
 
Oop concepts classes_objects
Oop concepts classes_objects
William Olivier
 
Object oriented programming
Object oriented programming
sana younas
 
Object Oriented Programming Concepts
Object Oriented Programming Concepts
Abhigyan Singh Yadav
 
object oriented programming(oops)
object oriented programming(oops)
HANISHTHARWANI21BCE1
 
Object Oriented Program Class 12 Computer Science
Object Oriented Program Class 12 Computer Science
ShailendraPandey96
 
slidesgo-exploring-object-oriented-features-a-guide-to-object-creation-and-pr...
slidesgo-exploring-object-oriented-features-a-guide-to-object-creation-and-pr...
valleerinavadeep
 
Object Oriented Programming Principles
Object Oriented Programming Principles
Andrew Ferlitsch
 
L1-Introduction to OOPs concepts.pdf
L1-Introduction to OOPs concepts.pdf
BhanuJatinSingh
 
object oriented programming(PYTHON)
object oriented programming(PYTHON)
Jyoti shukla
 
Object Oriented Programming Class and Objects
Object Oriented Programming Class and Objects
rubini8582
 
Procedural-vs-Object-Oriented-Programming (1).pdf
Procedural-vs-Object-Oriented-Programming (1).pdf
AnujMalviya12
 
Python programming Concepts (Functions, classes and Oops concept
Python programming Concepts (Functions, classes and Oops concept
Lipika Sharma
 
Regex,functions, inheritance,class, attribute,overloding
Regex,functions, inheritance,class, attribute,overloding
sangumanikesh
 
Understanding the Basics of Object-Oriented Programming for Beginners
Understanding the Basics of Object-Oriented Programming for Beginners
Emma Jacob
 
CPP_,module2_1.pptx
CPP_,module2_1.pptx
AbhilashTom4
 
Introduction to OOP_Python_Lecture1.pptx
Introduction to OOP_Python_Lecture1.pptx
cpics
 
Principles and advantages of oop ppt
Principles and advantages of oop ppt
daxesh chauhan
 
Oop concepts classes_objects
Oop concepts classes_objects
William Olivier
 
Object oriented programming
Object oriented programming
sana younas
 
Object Oriented Programming Concepts
Object Oriented Programming Concepts
Abhigyan Singh Yadav
 
Object Oriented Program Class 12 Computer Science
Object Oriented Program Class 12 Computer Science
ShailendraPandey96
 
slidesgo-exploring-object-oriented-features-a-guide-to-object-creation-and-pr...
slidesgo-exploring-object-oriented-features-a-guide-to-object-creation-and-pr...
valleerinavadeep
 

Recently uploaded (20)

Pavement and its types, Application of rigid and Flexible Pavements
Pavement and its types, Application of rigid and Flexible Pavements
Sakthivel M
 
Low Power SI Class E Power Amplifier and Rf Switch for Health Care
Low Power SI Class E Power Amplifier and Rf Switch for Health Care
ieijjournal
 
社内勉強会資料_Chain of Thought .
社内勉強会資料_Chain of Thought .
NABLAS株式会社
 
Fundamentals of Digital Design_Class_12th April.pptx
Fundamentals of Digital Design_Class_12th April.pptx
drdebarshi1993
 
IntroSlides-June-GDG-Cloud-Munich community [email protected]
IntroSlides-June-GDG-Cloud-Munich community [email protected]
Luiz Carneiro
 
chemistry investigatory project for class 12
chemistry investigatory project for class 12
Susis10
 
machine learning is a advance technology
machine learning is a advance technology
ynancy893
 
3. What is the principles of Teamwork_Module_V1.0.ppt
3. What is the principles of Teamwork_Module_V1.0.ppt
engaash9
 
Development of Portable Biomass Briquetting Machine (S, A & D)-1.pptx
Development of Portable Biomass Briquetting Machine (S, A & D)-1.pptx
aniket862935
 
NALCO Green Anode Plant,Compositions of CPC,Pitch
NALCO Green Anode Plant,Compositions of CPC,Pitch
arpitprachi123
 
最新版美国圣莫尼卡学院毕业证(SMC毕业证书)原版定制
最新版美国圣莫尼卡学院毕业证(SMC毕业证书)原版定制
Taqyea
 
The basics of hydrogenation of co2 reaction
The basics of hydrogenation of co2 reaction
kumarrahul230759
 
Deep Learning for Natural Language Processing_FDP on 16 June 2025 MITS.pptx
Deep Learning for Natural Language Processing_FDP on 16 June 2025 MITS.pptx
resming1
 
Modern multi-proposer consensus implementations
Modern multi-proposer consensus implementations
François Garillot
 
Industry 4.o the fourth revolutionWeek-2.pptx
Industry 4.o the fourth revolutionWeek-2.pptx
KNaveenKumarECE
 
362 Alec Data Center Solutions-Slysium Data Center-AUH-Glands & Lugs, Simplex...
362 Alec Data Center Solutions-Slysium Data Center-AUH-Glands & Lugs, Simplex...
djiceramil
 
Structural Design for Residential-to-Restaurant Conversion
Structural Design for Residential-to-Restaurant Conversion
DanielRoman285499
 
362 Alec Data Center Solutions-Slysium Data Center-AUH-ABB Furse.pdf
362 Alec Data Center Solutions-Slysium Data Center-AUH-ABB Furse.pdf
djiceramil
 
Cadastral Maps
Cadastral Maps
Google
 
20CE601- DESIGN OF STEEL STRUCTURES ,INTRODUCTION AND ALLOWABLE STRESS DESIGN
20CE601- DESIGN OF STEEL STRUCTURES ,INTRODUCTION AND ALLOWABLE STRESS DESIGN
gowthamvicky1
 
Pavement and its types, Application of rigid and Flexible Pavements
Pavement and its types, Application of rigid and Flexible Pavements
Sakthivel M
 
Low Power SI Class E Power Amplifier and Rf Switch for Health Care
Low Power SI Class E Power Amplifier and Rf Switch for Health Care
ieijjournal
 
社内勉強会資料_Chain of Thought .
社内勉強会資料_Chain of Thought .
NABLAS株式会社
 
Fundamentals of Digital Design_Class_12th April.pptx
Fundamentals of Digital Design_Class_12th April.pptx
drdebarshi1993
 
chemistry investigatory project for class 12
chemistry investigatory project for class 12
Susis10
 
machine learning is a advance technology
machine learning is a advance technology
ynancy893
 
3. What is the principles of Teamwork_Module_V1.0.ppt
3. What is the principles of Teamwork_Module_V1.0.ppt
engaash9
 
Development of Portable Biomass Briquetting Machine (S, A & D)-1.pptx
Development of Portable Biomass Briquetting Machine (S, A & D)-1.pptx
aniket862935
 
NALCO Green Anode Plant,Compositions of CPC,Pitch
NALCO Green Anode Plant,Compositions of CPC,Pitch
arpitprachi123
 
最新版美国圣莫尼卡学院毕业证(SMC毕业证书)原版定制
最新版美国圣莫尼卡学院毕业证(SMC毕业证书)原版定制
Taqyea
 
The basics of hydrogenation of co2 reaction
The basics of hydrogenation of co2 reaction
kumarrahul230759
 
Deep Learning for Natural Language Processing_FDP on 16 June 2025 MITS.pptx
Deep Learning for Natural Language Processing_FDP on 16 June 2025 MITS.pptx
resming1
 
Modern multi-proposer consensus implementations
Modern multi-proposer consensus implementations
François Garillot
 
Industry 4.o the fourth revolutionWeek-2.pptx
Industry 4.o the fourth revolutionWeek-2.pptx
KNaveenKumarECE
 
362 Alec Data Center Solutions-Slysium Data Center-AUH-Glands & Lugs, Simplex...
362 Alec Data Center Solutions-Slysium Data Center-AUH-Glands & Lugs, Simplex...
djiceramil
 
Structural Design for Residential-to-Restaurant Conversion
Structural Design for Residential-to-Restaurant Conversion
DanielRoman285499
 
362 Alec Data Center Solutions-Slysium Data Center-AUH-ABB Furse.pdf
362 Alec Data Center Solutions-Slysium Data Center-AUH-ABB Furse.pdf
djiceramil
 
Cadastral Maps
Cadastral Maps
Google
 
20CE601- DESIGN OF STEEL STRUCTURES ,INTRODUCTION AND ALLOWABLE STRESS DESIGN
20CE601- DESIGN OF STEEL STRUCTURES ,INTRODUCTION AND ALLOWABLE STRESS DESIGN
gowthamvicky1
 
Ad

Object Oriented Programming_combined.ppt.pdf

  • 1. Introduction to Object Oriented Programming Gayathri Namasivayam Introduction to OOP
  • 2. Topics ●Why use OOP? ●Building blocks of OOP ● Classes ● Objects ●What is OOP? ●OOP concepts ● Abstraction ● Encapsulation ● Inheritance ● Polymorphism ●Advantages vs Disadvantages ●Conclusion Introduction to OOP
  • 3. Topics ●Why use OOP? ●Building blocks of OOP ● Classes ● Objects ●What is OOP? ●OOP concepts ● Abstraction ● Encapsulation ● Inheritance ● Polymorphism ●Advantages vs Disadvantages ●Conclusion Introduction to OOP
  • 4. Why use OOP? ●Object Oriented Programming (OOP) is one of the most widely used programming paradigm ●Why is it extensively used? ● Well suited for building trivial and complex applications ● Allows re-use of code thereby increasing productivity ● New features can be easily built into the existing code ● Reduced production cost and maintenance cost ●Common programming languages used for OOP include C++, Java, and C# Introduction to OOP
  • 5. Topics ●Why use OOP? ●Building blocks of OOP ● Classes ● Objects ●What is OOP? ●OOP concepts ● Abstraction ● Encapsulation ● Inheritance ● Polymorphism ●Advantages vs Disadvantages ●Conclusion Introduction to OOP
  • 6. Building Blocks of OOP: Objects & Classes ●Object: models a ● Real world object (ex. computer, book, box) ● Concept (ex. meeting, interview) ● Process (ex. sorting a stack of papers or comparing two computers to measure their performance) ●Class: prototype or blueprint from which objects are created Introduction to OOP
  • 7. Building Blocks of OOP: Objects & Classes ●Class has ● Set of attributes or properties that describes every object ● Set of behavior or actions that every object can perform ●Object has ● Set of data (value for each of its attribute) ● Set of actions that it can perform ● An identity ●Every object belongs to a class Introduction to OOP
  • 8. Real World Example of Objects & Classes 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 Introduction to OOP
  • 9. Another Real World Example.. 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 Introduction to OOP
  • 10. Class ●A class is a set of variables (to represent its attributes) and functions (to describe its behavior) that act on its variables Introduction to OOP
  • 11. Class ShippingBox int shipping_cost() { return cost_per_pound*weight; } sender_name : string receiver_name : string cost_per_pound : int weight : int shipping_cost() : int Introduction to OOP
  • 12. Object ●Object is an instance of a class that holds data (values) in its variables. Data can be accessed by its functions Introduction to OOP
  • 13. Objects of ShippingBox class 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 Introduction to OOP
  • 14. Topics ●Why use OOP? ●Building blocks of OOP ● Classes ● Objects ●What is OOP? ●OOP concepts ● Abstraction ● Encapsulation ● Inheritance ● Polymorphism ●Advantages vs Disadvantages ●Conclusion Introduction to OOP
  • 15. What is OOP? ●Paradigm for problem solving by interaction among objects ●It follows a natural way of solving problems ● Ex. Ann wants to start her car (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
  • 16. Problem Solving in OOP Problem: Ann wants to start her car 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 Introduction to OOP
  • 17. Topics ●Why use OOP? ●Building blocks of OOP ● Classes ● Objects ●What is OOP? ●OOP concepts ● Abstraction ● Encapsulation ● Inheritance ● Polymorphism ●Advantages vs Disadvantages ●Conclusion Introduction to OOP
  • 18. Abstraction ●Extracting essential properties and behavior of an entity ●Class represents such an abstraction and is commonly referred to as an abstract data type 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() Introduction to OOP
  • 19. Abstraction 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 Introduction to OOP
  • 20. Topics ●Why use OOP? ●Building blocks of OOP ● Classes ● Objects ●What is OOP? ●OOP concepts ● Abstraction ● Encapsulation ● Inheritance ● Polymorphism ●Advantages vs Disadvantages ●Conclusion Introduction to OOP
  • 21. Encapsulation sender_name receiver_name cost_per_pound weight shipping_cost() ●Mechanism by which we combine data and the functions that manipulate the data into one unit ●Objects & Classes enforce encapsulation Introduction to OOP
  • 22. Topics ●Why use OOP? ●Building blocks of OOP ● Classes ● Objects ●What is OOP? ●OOP concepts ● Abstraction ● Encapsulation ● Inheritance ● Polymorphism ●Advantages vs Disadvantages ●Conclusion Introduction to OOP
  • 23. Inheritance ●Create new classes (derived classes) from existing classes (base classes) ●The derived class inherits the variables and functions of the base class and adds additional ones! ●Provides the ability to re-use existing code Introduction to OOP
  • 24. Inheritance Example BankAccount CheckingAccount SavingsAccount 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 Introduction to OOP
  • 25. Inheritance Example 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 Introduction to OOP
  • 26. Topics ●Why use OOP? ●Building blocks of OOP ● Classes ● Objects ●What is OOP? ●OOP concepts ● Abstraction ● Encapsulation ● Inheritance ● Polymorphism* ●Advantages vs Disadvantages ●Conclusion (* To be covered in the next class) Introduction to OOP
  • 27. Disadvantages of OOP ●Initial extra effort needed in accurately modeling the classes and sub-classes for a problem ●Suited for modeling certain real world problems as opposed to some others Introduction to OOP
  • 28. Conclusion ●Classes & Objects ●Concepts in OOP ● Abstraction ● Encapsulation ● Inheritance ●Advantages & Disadvantages ●Next class ● Be prepared for an in-class activity (based on topics covered today)! ● Polymorphism in OOP! Introduction to OOP