SlideShare a Scribd company logo
1 of 90
CS-………………….
 Objective of this course is to make students
familiar with the concepts of object-oriented
programming
 Concepts will be reinforced by their
implementation in C++
 Object-Orientation
 Objects and Classes
 Overloading
 Inheritance
 Polymorphism
 Generic Programming
 Exception Handling
 Introduction to Design Patterns
 C++ How to Program
By Deitel & Deitel
 The C++ Programming Language
By Bjarne Stroustrup
 Object-Oriented Software Engineering
By Jacobson, Christerson, Jonsson, Overgaard
 Assignments 15 %
 Group Discussion 5 %
 Mid-Term 35 %
 Final 45 %
 A technique for system modeling
 OO model consists of several interacting
objects
 A model is an abstraction of something
 Purpose is to understand the product before
developing it
 Highway maps
 Architectural models
 Mechanical models
 Objects
 Ali
 House
 Car
 Tree
 Interactions
 Ali lives in the house
 Ali drives the car
Ali
Car
House
Tree
lives-in
drives
 People think in terms of objects
 OO models map to reality
 Therefore, OO models are
 easy to develop
 easy to understand
An object is
 Something tangible (Ali, Car)
 Something that can be apprehended
intellectually (Time, Date)
An object has
 State (attributes)
 Well-defined behaviour (operations)
 Unique identity
 State (attributes)
 Name
 Age
 behaviour (operations)
 Walks
 Eats
 Identity
 His name
 State (attributes)
- Color
- Model
 behaviour (operations)
- Accelerate - Start Car
- Change Gear
 Identity
- Its registration number
 State (attributes)
- Hours - Seconds
- Minutes
 behaviour (operations)
- Set Hours - Set Seconds
- Set Minutes
 Identity
- Would have a unique ID in the model
 State (attributes)
- Year - Day
- Month
 behaviour (operations)
- Set Year - Set Day
- Set Month
 Identity
- Would have a unique ID in the model
 Information is stored within the object
 It is hidden from the outside world
 It can only be manipulated by the object itself
 Ali’s name is stored within his brain
 We can’t access his name directly
 Rather we can ask him to tell his name
 A phone stores several phone numbers
 We can’t read the numbers directly from the
SIM card
 Rather phone-set reads this information for us
 Simplifies the model by hiding implementation
details
 It is a barrier against change propagation
 Data and behaviour are tightly coupled inside
an object
 Both the information structure and
implementation details of its operations are
hidden from the outer world
 Ali stores his personal information and knows
how to translate it to the desired language
 We don’t know
 How the data is stored
 How Ali translates this information
 A Phone stores phone numbers in digital
format and knows how to convert it into
human-readable characters
 We don’t know
 How the data is stored
 How it is converted to human-readable characters
 Simplicity and clarity
 Low complexity
 Better understanding
 An object encapsulates data and behaviour
 So how objects interact with each other?
 Each object provides an interface (operations)
 Other objects communicate through this
interface
 Steer Wheels
 Accelerate
 Change Gear
 Apply Brakes
 Turn Lights On/Off
 Input Number
 Place Call
 Disconnect Call
 Add number to address book
 Remove number
 Update number
 Provides services offered by the object interface
 This includes
 Data structures to hold object state
 Functionality that provides required services
 Data Structure
 Mechanical structure of gear box
 Functionality
 Mechanism to change gear
 Data Structure
 SIM card
 Functionality
 Read/write circuitry
 Means change in implementation does not
effect object interface
 This is achieved via principles of information
hiding and encapsulation
 A driver can drive a car independent of engine
type (petrol, diesel)
 Because interface does not change with the
implementation
 A driver can apply brakes independent of
brakes type (simple, disk)
 Again, reason is the same interface
 Users need not to worry about a change until
the interface is same
 Low Complexity
 Direct access to information structure of an
object can produce errors
 Objects communicate through messages
 They send messages (stimuli) by invoking
appropriate operations on the target object
 The number and kind of messages that can be
sent to an object depends upon its interface
 A Person sends message (stimulus) “stop” to a
Car by applying brakes
 A Person sends message “place call” to a Phone
by pressing appropriate button
 Abstraction is a way to cope with complexity.
 Principle of abstraction:
“Capture only those details about an object that
are relevant to current perspective”
 Attributes
- Name - Employee ID
- Student Roll No - Designation
- Year of Study - Salary
- CGPA - Age
Ali is a PhD student and teaches BS students
 behaviour
- Study - DevelopExam
- GiveExam - TakeExam
- PlaySports - Eat
- DeliverLecture - Walk
Ali is a PhD student and teaches BS students
 Attributes
- Name - Employee ID
- Student Roll No - Designation
- Year of Study - Salary
- CGPA - Age
Student’s Perspective
 behaviour
- Study - DevelopExam
- GiveExam - TakeExam
- PlaySports - Eat
- DeliverLecture - Walk
Student’s Perspective
 Attributes
- Name - Employee ID
- Student Roll No - Designation
- Year of Study - Salary
- CGPA - Age
Teacher’s Perspective
 behaviour
- Study - DevelopExam
- GiveExam - TakeExam
- PlaySports - Eat
- DeliverLecture - Walk
Teacher’s Perspective
 Ordinary Perspective
A pet animal with
 Four Legs
 A Tail
 Two Ears
 Sharp Teeth
 Surgeon’s Perspective
A being with
 A Skeleton
 Heart
 Kidney
 Stomach
A cat can be viewed with different
perspectives
Driver’s View
Engineer’s View
 Simplifies the model by hiding irrelevant
details
 Abstraction provides the freedom to defer
implementation decisions by avoiding
commitment to details
 In an OO model, some of the objects exhibit
identical characteristics (information structure
and behaviour)
 We say that they belong to the same class
 Ali studies mathematics
 Anam studies physics
 Sohail studies chemistry
 Each one is a Student
 We say these objects are instances of the Student
class
 Ahsan teaches mathematics
 Aamir teaches computer science
 Atif teaches physics
 Each one is a teacher
 We say these objects are instances of the
Teacher class
(Class Name)
(attributes)
(operations)
(Class Name)
Normal Form
Suppressed
Form
Circle
center
radius
draw
computeArea
Normal Form
Suppressed
Form
Circle
Person
name
age
gender
eat
walk
Normal Form
Suppressed
Form
Person
 A child inherits characteristics of its parents
 Besides inherited characteristics, a child may
have its own unique characteristics
 If a class B inherits from class A then it contains
all the characteristics (information structure
and behaviour) of class A
 The parent class is called base class and the
child class is called derived class
 Besides inherited characteristics, derived class
may have its own unique characteristics
Person
Teacher
Doctor
Student
Shape
Circle
Triangle
Line
 Each derived class is a special kind of its base
class
Person
name
age
gender
eat
walk
Teacher
designation
salary
teach
takeExam
Student
program
studyYear
study
heldExam
Doctor
designation
salary
checkUp
prescribe
Shape
color
coord
draw
rotate
setColor
Circle
radius
draw
computeArea
Line
length
draw
Triangle
angle
draw
computeArea
 Reuse
 Less redundancy
 Increased maintainability
 Main purpose of inheritance is reuse
 We can easily add new classes by inheriting
from existing classes
 Select an existing class closer to the desired
functionality
 Create a new class and inherit it from the selected
class
 Add to and/or modify the inherited functionality
Shape
color
coord
draw
rotate
setColor
Circle
radius
draw
computeArea
Line
length
draw
Triangle
angle
draw
computeArea
Person
name
age
gender
eat
walk
Teacher
designation
salary
teach
takeExam
Student
program
studyYear
study
heldExam
Doctor
designation
salary
checkUp
prescribe
Person
name
age
gender
eat
walk
Teacher
designation
salary
teach
takeExam
Student
program
studyYear
study
heldExam
Doctor
designation
salary
checkUp
prescribe
 Generalization
 Subtyping (extension)
 Specialization (restriction)
 In OO models, some classes may have common
characteristics
 We extract these features into a new class and
inherit original classes from this new class
 This concept is known as Generalization
Circle
color
vertices
radius
move
setColor
computeArea
Line
color
vertices
length
move
setColor
getLength
Triangle
color
vertices
angle
move
setColor
computeArea
Shape
color
vertices
move
setColor
Circle
radius
computeArea
Line
length
getLength
Triangle
angle
computeArea
Teacher
name
age
gender
designation
salary
teach
takeExam
eat
walk
Student
name
age
gender
program
studyYear
study
heldExam
eat
walk
Doctor
name
age
gender
designation
salary
checkUp
prescribe
eat
walk
Person
name
age
gender
eat
walk
Teacher
designation
salary
teach
takeExam
Student
program
studyYear
study
heldExam
Doctor
designation
salary
checkUp
prescribe
 We want to add a new class to an existing
model
 Find an existing class that already implements
some of the desired state and behaviour
 Inherit the new class from this class and add
unique behaviour to the new class
 Sub-typing means that derived class is
behaviourally compatible with the base class
 Behaviourally compatible means that base class
can be replaced by the derived class
Person
name
age
gender
eats
walks
Student
program
studyYear
study
takeExam
Shape
color
vertices
setColor
move
Circle
radius
computeCF
computeArea
 Specialization means that derived class is
behaviourally incompatible with the base class
 Behaviourally incompatible means that base
class can’t always be replaced by the derived
class
Person
age : [0..100]
…
Adult
age : [18..100]
…
setAge( a )
…
setAge( a )
…
age = a
If age < 18 then
error
else
age = a
IntegerSet
…
NaturalSet
…
add( elem )
…
add( elem )
…
add element
to the set
If elem < 1 then
error
else
add element
to the set
 A class may need to override the default
behaviour provided by its base class
 Reasons for overriding
 Provide behaviour specific to a derived class
 Extend the default behaviour
 Restrict the default behaviour
 Improve performance
Shape
color
vertices
draw
move
setColor
Circle
radius
draw
computeArea
Line
length
draw
Triangle
angle
draw
computeArea
Window
width
height
open
close
draw
DialogBox
controls
enable
draw
1- Invoke
Window’s draw
2- draw the dialog
box
IntegerSet
…
NaturalSet
…
add( elem )
…
add( elem )
…
Add element
to the set
If elem < 1 then
give error
else
Add element
to the set
 Class Circle overrides
rotate operation of
class Shape with a
Null operation.
Shape
color
coord
draw
rotate
setColor
Circle
radius
draw
rotate
 An abstract class implements an abstract
concept
 Main purpose is to be inherited by other classes
 Can’t be instantiated
 Promotes reuse
Teacher
Doctor
Student
 Here, Person is an abstract class
Person
name
age
gender
eat
walk
Bus
Truck
Car
 Here, Vehicle is an abstract class
Vehicle
color
model
accelerate
applyBrakes
 A concrete class implements a concrete concept
 Main purpose is to be instantiated
 Provides implementation details specific to the
domain context
 Here, Student, Teacher and Doctor are concrete
classes
Teacher
Doctor
Student
program
studyYear
study
heldExam
Person
• Here, Car, Bus and Truck are concrete
classes
Bus
Car
Vehicle
Truck
capacity
load
unload

More Related Content

Similar to OOP Lecture 01.pptx

Dad (Data Analysis And Design)
Dad (Data Analysis And Design)Dad (Data Analysis And Design)
Dad (Data Analysis And Design)
Jill Lyons
 
Database 3 Conceptual Modeling And Er
Database 3   Conceptual Modeling And ErDatabase 3   Conceptual Modeling And Er
Database 3 Conceptual Modeling And Er
Ashwani Kumar Ramani
 
Object Modelling Technique " ooad "
Object Modelling Technique  " ooad "Object Modelling Technique  " ooad "
Object Modelling Technique " ooad "
AchrafJbr
 
OOP programming
OOP programmingOOP programming
OOP programming
anhdbh
 
FORMALIZATION & DATA ABSTRACTION DURING USE CASE MODELING IN OBJECT ORIENTED ...
FORMALIZATION & DATA ABSTRACTION DURING USE CASE MODELING IN OBJECT ORIENTED ...FORMALIZATION & DATA ABSTRACTION DURING USE CASE MODELING IN OBJECT ORIENTED ...
FORMALIZATION & DATA ABSTRACTION DURING USE CASE MODELING IN OBJECT ORIENTED ...
cscpconf
 
Formalization & data abstraction during use case modeling in object oriented ...
Formalization & data abstraction during use case modeling in object oriented ...Formalization & data abstraction during use case modeling in object oriented ...
Formalization & data abstraction during use case modeling in object oriented ...
csandit
 

Similar to OOP Lecture 01.pptx (20)

Ooad notes
Ooad notesOoad notes
Ooad notes
 
Dad (Data Analysis And Design)
Dad (Data Analysis And Design)Dad (Data Analysis And Design)
Dad (Data Analysis And Design)
 
Cs 2352 object oriented analysis and design
Cs 2352 object oriented analysis and designCs 2352 object oriented analysis and design
Cs 2352 object oriented analysis and design
 
Oot
OotOot
Oot
 
Handout on Object orienetd Analysis and Design
Handout on Object orienetd Analysis and DesignHandout on Object orienetd Analysis and Design
Handout on Object orienetd Analysis and Design
 
Database 3 Conceptual Modeling And Er
Database 3   Conceptual Modeling And ErDatabase 3   Conceptual Modeling And Er
Database 3 Conceptual Modeling And Er
 
Lecture01
Lecture01Lecture01
Lecture01
 
CS8592-OOAD Lecture Notes Unit-1
CS8592-OOAD Lecture Notes Unit-1CS8592-OOAD Lecture Notes Unit-1
CS8592-OOAD Lecture Notes Unit-1
 
Object Modelling Technique " ooad "
Object Modelling Technique  " ooad "Object Modelling Technique  " ooad "
Object Modelling Technique " ooad "
 
Lecture 01 - Basic Concept About OOP With Python
Lecture 01 - Basic Concept About OOP With PythonLecture 01 - Basic Concept About OOP With Python
Lecture 01 - Basic Concept About OOP With Python
 
IT6701-Information Management Unit 1
IT6701-Information Management Unit 1IT6701-Information Management Unit 1
IT6701-Information Management Unit 1
 
Ooad unit – 1 introduction
Ooad unit – 1 introductionOoad unit – 1 introduction
Ooad unit – 1 introduction
 
Object oriented progrmming
Object oriented progrmmingObject oriented progrmming
Object oriented progrmming
 
OOP programming
OOP programmingOOP programming
OOP programming
 
C++123
C++123C++123
C++123
 
FORMALIZATION & DATA ABSTRACTION DURING USE CASE MODELING IN OBJECT ORIENTED ...
FORMALIZATION & DATA ABSTRACTION DURING USE CASE MODELING IN OBJECT ORIENTED ...FORMALIZATION & DATA ABSTRACTION DURING USE CASE MODELING IN OBJECT ORIENTED ...
FORMALIZATION & DATA ABSTRACTION DURING USE CASE MODELING IN OBJECT ORIENTED ...
 
Formalization & data abstraction during use case modeling in object oriented ...
Formalization & data abstraction during use case modeling in object oriented ...Formalization & data abstraction during use case modeling in object oriented ...
Formalization & data abstraction during use case modeling in object oriented ...
 
Ch.1 oop introduction, classes and objects
Ch.1 oop introduction, classes and objectsCh.1 oop introduction, classes and objects
Ch.1 oop introduction, classes and objects
 
Cs2305 programming paradigms lecturer notes
Cs2305   programming paradigms lecturer notesCs2305   programming paradigms lecturer notes
Cs2305 programming paradigms lecturer notes
 
Introduction to Machine Learning - WeCloudData
Introduction to Machine Learning - WeCloudDataIntroduction to Machine Learning - WeCloudData
Introduction to Machine Learning - WeCloudData
 

Recently uploaded

Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Medical / Health Care (+971588192166) Mifepristone and Misoprostol tablets 200mg
 

Recently uploaded (20)

WSO2CON 2024 - Unlocking the Identity: Embracing CIAM 2.0 for a Competitive A...
WSO2CON 2024 - Unlocking the Identity: Embracing CIAM 2.0 for a Competitive A...WSO2CON 2024 - Unlocking the Identity: Embracing CIAM 2.0 for a Competitive A...
WSO2CON 2024 - Unlocking the Identity: Embracing CIAM 2.0 for a Competitive A...
 
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
 
WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?
 
WSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - KeynoteWSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - Keynote
 
Announcing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareAnnouncing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK Software
 
WSO2CON 2024 - Designing Event-Driven Enterprises: Stories of Transformation
WSO2CON 2024 - Designing Event-Driven Enterprises: Stories of TransformationWSO2CON 2024 - Designing Event-Driven Enterprises: Stories of Transformation
WSO2CON 2024 - Designing Event-Driven Enterprises: Stories of Transformation
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
 
WSO2CON 2024 - Software Engineering for Digital Businesses
WSO2CON 2024 - Software Engineering for Digital BusinessesWSO2CON 2024 - Software Engineering for Digital Businesses
WSO2CON 2024 - Software Engineering for Digital Businesses
 
Driving Innovation: Scania's API Revolution with WSO2
Driving Innovation: Scania's API Revolution with WSO2Driving Innovation: Scania's API Revolution with WSO2
Driving Innovation: Scania's API Revolution with WSO2
 
AzureNativeQumulo_HPC_Cloud_Native_Benchmarks.pdf
AzureNativeQumulo_HPC_Cloud_Native_Benchmarks.pdfAzureNativeQumulo_HPC_Cloud_Native_Benchmarks.pdf
AzureNativeQumulo_HPC_Cloud_Native_Benchmarks.pdf
 
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
 
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
 
%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto
 
What Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationWhat Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the Situation
 
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
 
WSO2Con2024 - From Blueprint to Brilliance: WSO2's Guide to API-First Enginee...
WSO2Con2024 - From Blueprint to Brilliance: WSO2's Guide to API-First Enginee...WSO2Con2024 - From Blueprint to Brilliance: WSO2's Guide to API-First Enginee...
WSO2Con2024 - From Blueprint to Brilliance: WSO2's Guide to API-First Enginee...
 
WSO2Con2024 - Hello Choreo Presentation - Kanchana
WSO2Con2024 - Hello Choreo Presentation - KanchanaWSO2Con2024 - Hello Choreo Presentation - Kanchana
WSO2Con2024 - Hello Choreo Presentation - Kanchana
 
WSO2CON 2024 - Building a Digital Government in Uganda
WSO2CON 2024 - Building a Digital Government in UgandaWSO2CON 2024 - Building a Digital Government in Uganda
WSO2CON 2024 - Building a Digital Government in Uganda
 
WSO2CON2024 - Why Should You Consider Ballerina for Your Next Integration
WSO2CON2024 - Why Should You Consider Ballerina for Your Next IntegrationWSO2CON2024 - Why Should You Consider Ballerina for Your Next Integration
WSO2CON2024 - Why Should You Consider Ballerina for Your Next Integration
 

OOP Lecture 01.pptx