Professional Documents
Culture Documents
OOP File 02
OOP File 02
SLIDE 2
1
Recap: Object
Object: A person, you, your parents, the book you are reading, the car you drive, a
student, a place, a desk, a circle, a button, a bank account, a mobile phone number,
even a loan
Objects contain data and code (function) to manipulate that data
Objects interact by sending messages to one another
Object: student
DATA:
Name
DOB
Marks
CGPA
…..
FUNCTIONS:
Total()
Average()
Display()
2
Classes
> Classes are user-defined data types and behaves like built-in types
> Also we can treat a class as a template and abstract data types
(ADT)
4
Example – Class
5
Graphical Representation of Classes
(Class Name)
(Class Name)
(attributes)
Suppressed
(operations)
Form
Normal Form
6
Example – Graphical Representation of Classes
Student
name
Dob
Student
dept
marks Suppressed
Total()
Form
GPA()
Display()
Normal Form
7
Example – Graphical Representation of Classes
Teacher
name
Dob
Teacher
dept
designation Suppressed
Form
publication()
Display()
Normal Form
8
Example – Graphical Representation of Classes
Circle
center Circle
radius
Draw() Suppressed
computeArea() Form
Normal Form
9
Example – Graphical Representation of Classes
Person
name Person
age
gender Suppressed
Eat() Form
Walk()
Normal Form
10
Information (Data) Hiding
program
11
Example – Information Hiding
12
Example – Information Hiding
> We can’t read the numbers directly from the SIM card
13
Information Hiding-Advantages
14
Encapsulation
> Data and behavior (functions) are tightly coupled inside an object
of the class
— Data structure: represents the properties, the state, or characteristics of
objects
— Actions: permissible behaviors that are controlled through the member
functions
> Only those functions which are wrapped in the class can access the
data
15
Example – Encapsulation
> Ali stores his personal information (data) and knows how to
translate (actions by functions) it to the desired language
16
Example – Encapsulation
> A Phone stores phone numbers in digital format and knows how to
convert it into human-readable characters
17
Encapsulation – Advantages
18
Object has an Interface
19
Example – Interface of a Car
> Accelerate
20
Example – Interface of a Phone
> Input Number
22
Example – Implementation of Gear Box
> Functionality
— Mechanism to change gear
23
Example – Implementation of Address Book in a Phone
> Functionality
—Read/write circuitry
24
Messages Passing
29
Examples – Messages Passing
30
Abstraction
“Capture only those details about an object that are relevant to current
perspective”
31
Example – Abstraction
> Attributes
- Name - Employee ID
- Student Roll No - Designation
- Year of Study - Salary
- CGPA - Age
32
Example – Abstraction
> Behavior
- Study - DevelopExam
- GiveExam - TakeExam
- PlaySports - Eat
- DeliverLecture - Walk
33
Example – Abstraction
Student’s Perspective
> Attributes
- Name - Employee ID
- Student Roll No - Designation
- Year of Study - Salary
- CGPA - Age
34
Example – Abstraction
Student’s Perspective
> Behavior
- Study - DevelopExam
- GiveExam - TakeExam
- PlaySports - Eat
- DeliverLecture - Walk
35
Example – Abstraction
Teacher’s Perspective
> Attributes
- Name - Employee ID
- Student Roll No - Designation
- Year of Study - Salary
- CGPA - Age
36
Example – Abstraction
Teacher’s Perspective
> Behavior
- Study - -DevelopExam
- GiveExam - TakeExam
- PlaySports - Eat
- DeliverLecture - Walk
37
Example – Abstraction
38
Example – Abstraction
Engineer’s View
Driver’s View
39
Abstraction – Advantages
40