SlideShare a Scribd company logo
1 of 56
CSC241:
Object Oriented
Programming
Spring 2013
1. Starting OOP
Please turn OFF your Mobile Phones!
Sunday, July 2, 2023
Farhan Aadil
July
2,
2023
COMSATS
Institute
of
Information
Technology
1
Study Assignment
• I hope you did go through chapter 1 of both the books.
• How was the experience?
• What did you learn?
July
2,
2023
2
COMSATS
Institute
of
Information
Technology
Procedural vs. Object-Oriented
• Procedural
Withdraw, deposit, transfer
• Object Oriented
Customer, money, account
July
2,
2023
3
COMSATS
Institute
of
Information
Technology
Object-Orientation
(OO)
July
2,
2023
COMSATS
Institute
of
Information
Technology
4
What is Object-Orientation?
• A technique for system modeling
• OO model consists of several interacting objects
July
2,
2023
COMSATS
Institute
of
Information
Technology
5
What is a Model?
• A model is an abstraction of something
• Purpose is to understand the product before developing it
July
2,
2023
COMSATS
Institute
of
Information
Technology
6
Examples – Model
• Highway maps
• Architectural models
• Mechanical models
July
2,
2023
COMSATS
Institute
of
Information
Technology
7
Example – OO Model
July
2,
2023
COMSATS
Institute
of
Information
Technology
8
…Example – OO Model
• Objects
• Ali
• House
• Car
• Tree
• Interactions
• Ali lives in the house
• Ali drives the car
Ali
Car
House
Tree
lives-in
drives
July
2,
2023
COMSATS
Institute
of
Information
Technology
9
Object-Orientation -
Advantages
• People think in terms of objects
• OO models map to reality
• Therefore, OO models are
• easy to develop
• easy to understand
July
2,
2023
COMSATS
Institute
of
Information
Technology
10
What is an Object?
An object is
• Something tangible (Ali, Car)
• Something that can be apprehended intellectually (Time,
Date)
***Apprehended intellectually means taken mentally or
logically***
July
2,
2023
COMSATS
Institute
of
Information
Technology
11
… What is an Object?
An object has
• State (attributes)
• Well-defined behaviour (operations)
• Unique identity
July
2,
2023
COMSATS
Institute
of
Information
Technology
12
Example – Ali is a Tangible Object
• State (attributes)
• Name
• Age
• behavior (operations)
• Walks
• Eats
• Identity
• His name
July
2,
2023
COMSATS
Institute
of
Information
Technology
13
Example – Car is a Tangible Object
• State (attributes)
- Color
- Model
• behavior (operations)
- Start Car
- Accelerate
- Change Gear
• Identity
- Its registration number
July
2,
2023
COMSATS
Institute
of
Information
Technology
14
Example – Time is an Object
Apprehended Intellectually
• State (attributes)
- Hours - Seconds
- Minutes
• behaviour (operations)
- Set Hours - Set Seconds
- Set Minutes
• Identity
- Would have a unique ID in the model
July
2,
2023
COMSATS
Institute
of
Information
Technology
15
Example – Date is an Object
Apprehended Intellectually
• State (attributes)
- Year - Day
- Month
• behaviour (operations)
- Set Year - Set Day
- Set Month
• Identity
- Would have a unique ID in the model
July
2,
2023
COMSATS
Institute
of
Information
Technology
16
Definition
• What Is an Object?
• An object is a software bundle of related
variables and methods (functions). Software
objects are often used to model real-world
objects you find in everyday life.
• Objects are key to understanding object-oriented
technology. You can look around you now and
see many examples of real-world objects: dog,
desk, television set, bicycle.
July
2,
2023
17
COMSATS
Institute
of
Information
Technology
Real-world objects share two
characteristics
• They all have state and behavior
• dogs have state (name, color, breed, hungry) and behavior
(barking, fetching, and wagging tail).
• Bicycles have state (current gear, current pedal cadence, two
wheels, number of gears) and behavior (braking, accelerating,
slowing down, changing gears).
July
2,
2023
18
COMSATS
Institute
of
Information
Technology
Software objects are modeled after real-
world objects
• A software object maintains its state in one or more variables .
• A software object implements its behavior with methods . A
method is a function (subroutine) associated with an object.
July
2,
2023
19
COMSATS
Institute
of
Information
Technology
Can represent real-world objects by
using software objects.
• You might want to represent real-world dogs as
software objects in an animation program or a
real-world bicycle as a software object in the
program that controls an electronic exercise
bike.
• You can also use software objects to model
abstract concepts. For example, an event is a
common object used in GUI window systems to
represent the action of a user pressing a mouse
button or a key on the keyboard.
July
2,
2023
20
COMSATS
Institute
of
Information
Technology
Moving to new thinking …
• C is a procedural language. A procedure is a list of instructions.
• Very small programs (tens of lines) need no organization.
• As they get large (hundreds of lines), they are divided into functions.
• Functions are still lists of instructions.
• Dividing a program into functions gives a structure to the program
(hence structured programming).
July
2,
2023
21
COMSATS
Institute
of
Information
Technology
Moving to new thinking …
• C programming cannot do the following well:
• Functions have unrestricted access to global data.
• Data and Functions are unrelated; they do not form a logical group or
show any form of binding.
• Cannot model ‘real world’.
• In real world, we deal with objects like cars, people etc.
• Are such objects like ‘data’? Which data type describes a car, for
example?
• Are such objects like ‘functions’? What will a function car() do?
July
2,
2023
22
COMSATS
Institute
of
Information
Technology
Moving to new thinking …
• A real world object, e.g. car:
• Is its description purely the ability to have a ‘data type’ to represent its
specifications or ‘attributes’ only? For example what attributes describe
a car?
• So by having all these attributes ‘only’ do you know all about a car?
Would you buy a car by merely looking at these attributes and their
values?
• No! What else do you wish to have?
July
2,
2023
23
COMSATS
Institute
of
Information
Technology
Moving to new thinking …
• A real world object, e.g. car:
• Test drive! Right?
• What would you know through a test drive: how it ‘behaves’ in
response to various stimulus!
• How can it negotiate a speed brake, a speedy turn, full braking etc.
• Effectively, you wish to know how it ‘functions’.
• Behavior is like a function.
• So neither data nor functions, by themselves, model real-world
objects effectively.
July
2,
2023
24
COMSATS
Institute
of
Information
Technology
Object Oriented Approach …
• Neither data nor functions, by themselves, model real-world
objects effectively.
• OO languages (like C++) combine both ‘data’ and ‘functions that
operate on that data’ into a single unit, called ‘object’. Hence
‘encapsulating’ an entity.
• The objects functions are called member functions.
• Typically, data can be accessed through functions only. So data gets
‘hidden’.
• Data hiding ensures the data is not accidentally altered.
• Reference analogy of a growing company; 2 people vs 100
employee company.
• Objects communicate with each other by calling each other’s
member functions.
July
2,
2023
25
COMSATS
Institute
of
Information
Technology
Object Oriented Approach …
• OOP is all about ‘organization’ and not about program operation.
Most individual statements are similar to C statements. Member
functions may be very similar to C procedural functions.
• In C you used to think about functions.
• In C++ you should think about objects.
• Often objects in C++ are real-world analogies.(parallel)
• In C++ objects are ‘instances’ of ‘classes’. E.g. Honda City is an
instance of class car!
• Class serves as a cookie cutter and an object a cookie.
July
2,
2023
26
COMSATS
Institute
of
Information
Technology
Abstraction
• Abstraction is a way to cope with complexity.
• Principle of abstraction:
“Capture only those details about an object that are relevant to
current perspective”
July
2,
2023
COMSATS
Institute
of
Information
Technology
27
Example – Abstraction
• Attributes
- Name - Employee ID
- Student Roll No - Designation
- Year of Study - Salary
- CGPA - Age
Ali is a PhD student and teaches BS
students
July
2,
2023
COMSATS
Institute
of
Information
Technology
28
Example – Abstraction
Ali is a PhD student and teaches BS
students
• Behavior
- Study - Develop Exam
- Give Exam - Take Exam
- Play Sports - Eat
- Deliver Lecture - Walk
July
2,
2023
COMSATS
Institute
of
Information
Technology
29
Example – Abstraction
Attributes
• - Name - Employee ID
• - Student Roll No - Designation
• - Year of Study - Salary
• - CGPA - Age
Student’s Perspective
July
2,
2023
COMSATS
Institute
of
Information
Technology
30
Example – Abstraction
Student’s Perspective
• behavior
- Study - Develop Exam
- Give Exam - Take Exam
- Play Sports - Eat
- Deliver Lecture - Walk
July
2,
2023
COMSATS
Institute
of
Information
Technology
31
Example – Abstraction
• Attributes
- Name - Employee ID
- Student Roll No - Designation
- Year of Study - Salary
- CGPA - Age
Teacher’s Perspective
July
2,
2023
COMSATS
Institute
of
Information
Technology
32
Example – Abstraction
Teacher’s Perspective
• behaviour
- Study - Develop Exam
- Give Exam - Take Exam
- Play Sports - Eat
- Deliver Lecture - Walk
July
2,
2023
COMSATS
Institute
of
Information
Technology
33
Example – Abstraction
• 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
July
2,
2023
COMSATS
Institute
of
Information
Technology
34
Example – Abstraction
Driver’s View
Engineer’s View
July
2,
2023
COMSATS
Institute
of
Information
Technology
35
Abstraction – Advantages
• Simplifies the model by hiding irrelevant details
• Abstraction provides the freedom to defer implementation
decisions by avoiding commitment to details
July
2,
2023
COMSATS
Institute
of
Information
Technology
36
Classes
• In an OO model, some of the objects exhibit identical
characteristics (information structure and behavior)
• We say that they belong to the same class
July
2,
2023
COMSATS
Institute
of
Information
Technology
37
Example – 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
July
2,
2023
COMSATS
Institute
of
Information
Technology
38
Example – 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
July
2,
2023
COMSATS
Institute
of
Information
Technology
39
Graphical Representation of Classes
(Class Name)
(attributes)
(operations)
(Class Name)
Normal Form
Suppressed
Form
July
2,
2023
COMSATS
Institute
of
Information
Technology
40
Example – Graphical Representation
of Classes
Circle
center
radius
draw
computeArea
Normal Form
Suppressed
Form
Circle
July
2,
2023
COMSATS
Institute
of
Information
Technology
41
Example – Graphical Representation
of Classes
Person
name
age
gender
eat
walk
Normal Form
Suppressed
Form
Person
July
2,
2023
COMSATS
Institute
of
Information
Technology
42
Inheritance
• A child inherits characteristics of its parents
• Besides inherited characteristics, a child may have its own
unique characteristics
July
2,
2023
COMSATS
Institute
of
Information
Technology
43
Inheritance in Classes
• 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
July
2,
2023
COMSATS
Institute
of
Information
Technology
44
Example – Inheritance
Person
Teacher
Doctor
Student
July
2,
2023
COMSATS
Institute
of
Information
Technology
45
Example – Inheritance
Shape
Circle
Triangle
Line
July
2,
2023
COMSATS
Institute
of
Information
Technology
46
Inheritance – “IS A” or
“IS A KIND OF” Relationship
• Each derived class is a special kind of its base class
July
2,
2023
COMSATS
Institute
of
Information
Technology
47
Example – “IS A” Relationship
Person
name
age
gender
eat
walk
Teacher
designation
salary
teach
takeExam
Student
program
studyYear
study
heldExam
Doctor
designation
salary
checkUp
prescribe
July
2,
2023
COMSATS
Institute
of
Information
Technology
48
Example – “IS A KIND”
Relationship
Shape
color
cord
draw
rotate
setColor
Circle
radius
draw
computeArea
Line
length
draw
Triangle
angle
draw
computeArea
July
2,
2023
COMSATS
Institute
of
Information
Technology
49
Inheritance – Advantages
• Reuse
• Less redundancy
• Increased maintainability
July
2,
2023
COMSATS
Institute
of
Information
Technology
50
Reuse with Inheritance
• 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
July
2,
2023
COMSATS
Institute
of
Information
Technology
51
Example Reuse
Shape
color
coord
draw
rotate
setColor
Circle
radius
draw
computeArea
Line
length
draw
Triangle
angle
draw
computeArea
July
2,
2023
COMSATS
Institute
of
Information
Technology
52
Example Reuse
Person
name
age
gender
eat
walk
Teacher
designation
salary
teach
takeExam
Student
program
studyYear
study
heldExam
Doctor
designation
salary
checkUp
prescribe
July
2,
2023
COMSATS
Institute
of
Information
Technology
53
Example Reuse
Person
name
age
gender
eat
walk
Teacher
designation
salary
teach
takeExam
Student
program
studyYear
study
heldExam
Doctor
designation
salary
checkUp
prescribe
July
2,
2023
COMSATS
Institute
of
Information
Technology
54
References
• “Object Oriented Programming in C++”, by “Robert Lafore”,
published by Sams Publishing (The Waite Group). 4th ed. available
in soft form.
• “Object Oriented Programming Using C++” by “Joyce Farrell” ,
published by Course Technology, Cengage Learning. 4th ed. available
in soft form
• National University of Computer & Emerging Sciences
[www.nu.edu.pk]
• Virtual University of Pakistan [ocw.vu.edu.pk]
• Open Courseware Consortium
[http://www.ocwconsortium.org/en/courses]
55
July
2,
2023
COMSATS
Institute
of
Information
Technology
Thanks
July
2,
2023
COMSATS
Institute
of
Information
Technology
56

More Related Content

Similar to CSC241 Object Oriented Programming Spring 2013

Object Modelling Technique " ooad "
Object Modelling Technique  " ooad "Object Modelling Technique  " ooad "
Object Modelling Technique " ooad "AchrafJbr
 
Topiary: A Tool for Prototyping Location-Enhanced Applications, at UIST 2004
Topiary: A Tool for Prototyping Location-Enhanced Applications, at UIST 2004Topiary: A Tool for Prototyping Location-Enhanced Applications, at UIST 2004
Topiary: A Tool for Prototyping Location-Enhanced Applications, at UIST 2004Jason Hong
 
Future of AI - 2023 07 25.pptx
Future of AI - 2023 07 25.pptxFuture of AI - 2023 07 25.pptx
Future of AI - 2023 07 25.pptxGreg Makowski
 
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 DesignSAFAD ISMAIL
 
ML UNIT-I.ppt
ML UNIT-I.pptML UNIT-I.ppt
ML UNIT-I.pptGskeitb
 
Computational Thinking in the Workforce and Next Generation Science Standards...
Computational Thinking in the Workforce and Next Generation Science Standards...Computational Thinking in the Workforce and Next Generation Science Standards...
Computational Thinking in the Workforce and Next Generation Science Standards...Josh Sheldon
 
UX in the Age of AI: Leading with Design
UX in the Age of AI: Leading with DesignUX in the Age of AI: Leading with Design
UX in the Age of AI: Leading with DesignUXPA International
 
UX in the Age of AI: Leading with Design UXPA2018
UX in the Age of AI: Leading with Design UXPA2018UX in the Age of AI: Leading with Design UXPA2018
UX in the Age of AI: Leading with Design UXPA2018Carol Smith
 
Reimagining authentic curriculum in the age of AI
Reimagining authentic curriculum in the age of AIReimagining authentic curriculum in the age of AI
Reimagining authentic curriculum in the age of AICharles Darwin University
 
AI_Session 1 Introduction to AI and intelligent agents.pptx
AI_Session 1 Introduction to AI and intelligent agents.pptxAI_Session 1 Introduction to AI and intelligent agents.pptx
AI_Session 1 Introduction to AI and intelligent agents.pptxAsst.prof M.Gokilavani
 
introduction to data science
introduction to data scienceintroduction to data science
introduction to data sciencebhavesh lande
 
Data Science-1 (1).ppt
Data Science-1 (1).pptData Science-1 (1).ppt
Data Science-1 (1).pptSanjayAcharaya
 
A_Presentation_Slide_of_SIWES_technical.pptx
A_Presentation_Slide_of_SIWES_technical.pptxA_Presentation_Slide_of_SIWES_technical.pptx
A_Presentation_Slide_of_SIWES_technical.pptxiwegbuebubechukwu9
 

Similar to CSC241 Object Oriented Programming Spring 2013 (20)

Object Modelling Technique " ooad "
Object Modelling Technique  " ooad "Object Modelling Technique  " ooad "
Object Modelling Technique " ooad "
 
Topiary: A Tool for Prototyping Location-Enhanced Applications, at UIST 2004
Topiary: A Tool for Prototyping Location-Enhanced Applications, at UIST 2004Topiary: A Tool for Prototyping Location-Enhanced Applications, at UIST 2004
Topiary: A Tool for Prototyping Location-Enhanced Applications, at UIST 2004
 
Future of AI - 2023 07 25.pptx
Future of AI - 2023 07 25.pptxFuture of AI - 2023 07 25.pptx
Future of AI - 2023 07 25.pptx
 
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
 
ML UNIT-I.ppt
ML UNIT-I.pptML UNIT-I.ppt
ML UNIT-I.ppt
 
Computational Thinking in the Workforce and Next Generation Science Standards...
Computational Thinking in the Workforce and Next Generation Science Standards...Computational Thinking in the Workforce and Next Generation Science Standards...
Computational Thinking in the Workforce and Next Generation Science Standards...
 
UX in the Age of AI: Leading with Design
UX in the Age of AI: Leading with DesignUX in the Age of AI: Leading with Design
UX in the Age of AI: Leading with Design
 
UX in the Age of AI: Leading with Design UXPA2018
UX in the Age of AI: Leading with Design UXPA2018UX in the Age of AI: Leading with Design UXPA2018
UX in the Age of AI: Leading with Design UXPA2018
 
Artificial Intelligence in Laymen Terms
Artificial Intelligence in Laymen TermsArtificial Intelligence in Laymen Terms
Artificial Intelligence in Laymen Terms
 
Reimagining authentic curriculum in the age of AI
Reimagining authentic curriculum in the age of AIReimagining authentic curriculum in the age of AI
Reimagining authentic curriculum in the age of AI
 
Data-X-Sparse-v2
Data-X-Sparse-v2Data-X-Sparse-v2
Data-X-Sparse-v2
 
AI_Session 1 Introduction to AI and intelligent agents.pptx
AI_Session 1 Introduction to AI and intelligent agents.pptxAI_Session 1 Introduction to AI and intelligent agents.pptx
AI_Session 1 Introduction to AI and intelligent agents.pptx
 
introduction to data science
introduction to data scienceintroduction to data science
introduction to data science
 
00-01 DSnDA.pdf
00-01 DSnDA.pdf00-01 DSnDA.pdf
00-01 DSnDA.pdf
 
Data Science-1 (1).ppt
Data Science-1 (1).pptData Science-1 (1).ppt
Data Science-1 (1).ppt
 
Data-X-v3.1
Data-X-v3.1Data-X-v3.1
Data-X-v3.1
 
introduction.pdf
introduction.pdfintroduction.pdf
introduction.pdf
 
AI_Session 2 Types of AI agent.pptx
AI_Session 2 Types of AI agent.pptxAI_Session 2 Types of AI agent.pptx
AI_Session 2 Types of AI agent.pptx
 
Introduction
IntroductionIntroduction
Introduction
 
A_Presentation_Slide_of_SIWES_technical.pptx
A_Presentation_Slide_of_SIWES_technical.pptxA_Presentation_Slide_of_SIWES_technical.pptx
A_Presentation_Slide_of_SIWES_technical.pptx
 

Recently uploaded

BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application ) Sakshi Ghasle
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
Science lesson Moon for 4th quarter lesson
Science lesson Moon for 4th quarter lessonScience lesson Moon for 4th quarter lesson
Science lesson Moon for 4th quarter lessonJericReyAuditor
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxAvyJaneVismanos
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
Biting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfBiting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfadityarao40181
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaVirag Sontakke
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,Virag Sontakke
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting DataJhengPantaleon
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 

Recently uploaded (20)

BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application )
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
Science lesson Moon for 4th quarter lesson
Science lesson Moon for 4th quarter lessonScience lesson Moon for 4th quarter lesson
Science lesson Moon for 4th quarter lesson
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptx
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
Biting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfBiting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdf
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of India
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 

CSC241 Object Oriented Programming Spring 2013

  • 1. CSC241: Object Oriented Programming Spring 2013 1. Starting OOP Please turn OFF your Mobile Phones! Sunday, July 2, 2023 Farhan Aadil July 2, 2023 COMSATS Institute of Information Technology 1
  • 2. Study Assignment • I hope you did go through chapter 1 of both the books. • How was the experience? • What did you learn? July 2, 2023 2 COMSATS Institute of Information Technology
  • 3. Procedural vs. Object-Oriented • Procedural Withdraw, deposit, transfer • Object Oriented Customer, money, account July 2, 2023 3 COMSATS Institute of Information Technology
  • 5. What is Object-Orientation? • A technique for system modeling • OO model consists of several interacting objects July 2, 2023 COMSATS Institute of Information Technology 5
  • 6. What is a Model? • A model is an abstraction of something • Purpose is to understand the product before developing it July 2, 2023 COMSATS Institute of Information Technology 6
  • 7. Examples – Model • Highway maps • Architectural models • Mechanical models July 2, 2023 COMSATS Institute of Information Technology 7
  • 8. Example – OO Model July 2, 2023 COMSATS Institute of Information Technology 8
  • 9. …Example – OO Model • Objects • Ali • House • Car • Tree • Interactions • Ali lives in the house • Ali drives the car Ali Car House Tree lives-in drives July 2, 2023 COMSATS Institute of Information Technology 9
  • 10. Object-Orientation - Advantages • People think in terms of objects • OO models map to reality • Therefore, OO models are • easy to develop • easy to understand July 2, 2023 COMSATS Institute of Information Technology 10
  • 11. What is an Object? An object is • Something tangible (Ali, Car) • Something that can be apprehended intellectually (Time, Date) ***Apprehended intellectually means taken mentally or logically*** July 2, 2023 COMSATS Institute of Information Technology 11
  • 12. … What is an Object? An object has • State (attributes) • Well-defined behaviour (operations) • Unique identity July 2, 2023 COMSATS Institute of Information Technology 12
  • 13. Example – Ali is a Tangible Object • State (attributes) • Name • Age • behavior (operations) • Walks • Eats • Identity • His name July 2, 2023 COMSATS Institute of Information Technology 13
  • 14. Example – Car is a Tangible Object • State (attributes) - Color - Model • behavior (operations) - Start Car - Accelerate - Change Gear • Identity - Its registration number July 2, 2023 COMSATS Institute of Information Technology 14
  • 15. Example – Time is an Object Apprehended Intellectually • State (attributes) - Hours - Seconds - Minutes • behaviour (operations) - Set Hours - Set Seconds - Set Minutes • Identity - Would have a unique ID in the model July 2, 2023 COMSATS Institute of Information Technology 15
  • 16. Example – Date is an Object Apprehended Intellectually • State (attributes) - Year - Day - Month • behaviour (operations) - Set Year - Set Day - Set Month • Identity - Would have a unique ID in the model July 2, 2023 COMSATS Institute of Information Technology 16
  • 17. Definition • What Is an Object? • An object is a software bundle of related variables and methods (functions). Software objects are often used to model real-world objects you find in everyday life. • Objects are key to understanding object-oriented technology. You can look around you now and see many examples of real-world objects: dog, desk, television set, bicycle. July 2, 2023 17 COMSATS Institute of Information Technology
  • 18. Real-world objects share two characteristics • They all have state and behavior • dogs have state (name, color, breed, hungry) and behavior (barking, fetching, and wagging tail). • Bicycles have state (current gear, current pedal cadence, two wheels, number of gears) and behavior (braking, accelerating, slowing down, changing gears). July 2, 2023 18 COMSATS Institute of Information Technology
  • 19. Software objects are modeled after real- world objects • A software object maintains its state in one or more variables . • A software object implements its behavior with methods . A method is a function (subroutine) associated with an object. July 2, 2023 19 COMSATS Institute of Information Technology
  • 20. Can represent real-world objects by using software objects. • You might want to represent real-world dogs as software objects in an animation program or a real-world bicycle as a software object in the program that controls an electronic exercise bike. • You can also use software objects to model abstract concepts. For example, an event is a common object used in GUI window systems to represent the action of a user pressing a mouse button or a key on the keyboard. July 2, 2023 20 COMSATS Institute of Information Technology
  • 21. Moving to new thinking … • C is a procedural language. A procedure is a list of instructions. • Very small programs (tens of lines) need no organization. • As they get large (hundreds of lines), they are divided into functions. • Functions are still lists of instructions. • Dividing a program into functions gives a structure to the program (hence structured programming). July 2, 2023 21 COMSATS Institute of Information Technology
  • 22. Moving to new thinking … • C programming cannot do the following well: • Functions have unrestricted access to global data. • Data and Functions are unrelated; they do not form a logical group or show any form of binding. • Cannot model ‘real world’. • In real world, we deal with objects like cars, people etc. • Are such objects like ‘data’? Which data type describes a car, for example? • Are such objects like ‘functions’? What will a function car() do? July 2, 2023 22 COMSATS Institute of Information Technology
  • 23. Moving to new thinking … • A real world object, e.g. car: • Is its description purely the ability to have a ‘data type’ to represent its specifications or ‘attributes’ only? For example what attributes describe a car? • So by having all these attributes ‘only’ do you know all about a car? Would you buy a car by merely looking at these attributes and their values? • No! What else do you wish to have? July 2, 2023 23 COMSATS Institute of Information Technology
  • 24. Moving to new thinking … • A real world object, e.g. car: • Test drive! Right? • What would you know through a test drive: how it ‘behaves’ in response to various stimulus! • How can it negotiate a speed brake, a speedy turn, full braking etc. • Effectively, you wish to know how it ‘functions’. • Behavior is like a function. • So neither data nor functions, by themselves, model real-world objects effectively. July 2, 2023 24 COMSATS Institute of Information Technology
  • 25. Object Oriented Approach … • Neither data nor functions, by themselves, model real-world objects effectively. • OO languages (like C++) combine both ‘data’ and ‘functions that operate on that data’ into a single unit, called ‘object’. Hence ‘encapsulating’ an entity. • The objects functions are called member functions. • Typically, data can be accessed through functions only. So data gets ‘hidden’. • Data hiding ensures the data is not accidentally altered. • Reference analogy of a growing company; 2 people vs 100 employee company. • Objects communicate with each other by calling each other’s member functions. July 2, 2023 25 COMSATS Institute of Information Technology
  • 26. Object Oriented Approach … • OOP is all about ‘organization’ and not about program operation. Most individual statements are similar to C statements. Member functions may be very similar to C procedural functions. • In C you used to think about functions. • In C++ you should think about objects. • Often objects in C++ are real-world analogies.(parallel) • In C++ objects are ‘instances’ of ‘classes’. E.g. Honda City is an instance of class car! • Class serves as a cookie cutter and an object a cookie. July 2, 2023 26 COMSATS Institute of Information Technology
  • 27. Abstraction • Abstraction is a way to cope with complexity. • Principle of abstraction: “Capture only those details about an object that are relevant to current perspective” July 2, 2023 COMSATS Institute of Information Technology 27
  • 28. Example – Abstraction • Attributes - Name - Employee ID - Student Roll No - Designation - Year of Study - Salary - CGPA - Age Ali is a PhD student and teaches BS students July 2, 2023 COMSATS Institute of Information Technology 28
  • 29. Example – Abstraction Ali is a PhD student and teaches BS students • Behavior - Study - Develop Exam - Give Exam - Take Exam - Play Sports - Eat - Deliver Lecture - Walk July 2, 2023 COMSATS Institute of Information Technology 29
  • 30. Example – Abstraction Attributes • - Name - Employee ID • - Student Roll No - Designation • - Year of Study - Salary • - CGPA - Age Student’s Perspective July 2, 2023 COMSATS Institute of Information Technology 30
  • 31. Example – Abstraction Student’s Perspective • behavior - Study - Develop Exam - Give Exam - Take Exam - Play Sports - Eat - Deliver Lecture - Walk July 2, 2023 COMSATS Institute of Information Technology 31
  • 32. Example – Abstraction • Attributes - Name - Employee ID - Student Roll No - Designation - Year of Study - Salary - CGPA - Age Teacher’s Perspective July 2, 2023 COMSATS Institute of Information Technology 32
  • 33. Example – Abstraction Teacher’s Perspective • behaviour - Study - Develop Exam - Give Exam - Take Exam - Play Sports - Eat - Deliver Lecture - Walk July 2, 2023 COMSATS Institute of Information Technology 33
  • 34. Example – Abstraction • 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 July 2, 2023 COMSATS Institute of Information Technology 34
  • 35. Example – Abstraction Driver’s View Engineer’s View July 2, 2023 COMSATS Institute of Information Technology 35
  • 36. Abstraction – Advantages • Simplifies the model by hiding irrelevant details • Abstraction provides the freedom to defer implementation decisions by avoiding commitment to details July 2, 2023 COMSATS Institute of Information Technology 36
  • 37. Classes • In an OO model, some of the objects exhibit identical characteristics (information structure and behavior) • We say that they belong to the same class July 2, 2023 COMSATS Institute of Information Technology 37
  • 38. Example – 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 July 2, 2023 COMSATS Institute of Information Technology 38
  • 39. Example – 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 July 2, 2023 COMSATS Institute of Information Technology 39
  • 40. Graphical Representation of Classes (Class Name) (attributes) (operations) (Class Name) Normal Form Suppressed Form July 2, 2023 COMSATS Institute of Information Technology 40
  • 41. Example – Graphical Representation of Classes Circle center radius draw computeArea Normal Form Suppressed Form Circle July 2, 2023 COMSATS Institute of Information Technology 41
  • 42. Example – Graphical Representation of Classes Person name age gender eat walk Normal Form Suppressed Form Person July 2, 2023 COMSATS Institute of Information Technology 42
  • 43. Inheritance • A child inherits characteristics of its parents • Besides inherited characteristics, a child may have its own unique characteristics July 2, 2023 COMSATS Institute of Information Technology 43
  • 44. Inheritance in Classes • 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 July 2, 2023 COMSATS Institute of Information Technology 44
  • 47. Inheritance – “IS A” or “IS A KIND OF” Relationship • Each derived class is a special kind of its base class July 2, 2023 COMSATS Institute of Information Technology 47
  • 48. Example – “IS A” Relationship Person name age gender eat walk Teacher designation salary teach takeExam Student program studyYear study heldExam Doctor designation salary checkUp prescribe July 2, 2023 COMSATS Institute of Information Technology 48
  • 49. Example – “IS A KIND” Relationship Shape color cord draw rotate setColor Circle radius draw computeArea Line length draw Triangle angle draw computeArea July 2, 2023 COMSATS Institute of Information Technology 49
  • 50. Inheritance – Advantages • Reuse • Less redundancy • Increased maintainability July 2, 2023 COMSATS Institute of Information Technology 50
  • 51. Reuse with Inheritance • 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 July 2, 2023 COMSATS Institute of Information Technology 51
  • 55. References • “Object Oriented Programming in C++”, by “Robert Lafore”, published by Sams Publishing (The Waite Group). 4th ed. available in soft form. • “Object Oriented Programming Using C++” by “Joyce Farrell” , published by Course Technology, Cengage Learning. 4th ed. available in soft form • National University of Computer & Emerging Sciences [www.nu.edu.pk] • Virtual University of Pakistan [ocw.vu.edu.pk] • Open Courseware Consortium [http://www.ocwconsortium.org/en/courses] 55 July 2, 2023 COMSATS Institute of Information Technology