Professional Documents
Culture Documents
Object Oriented
Programming
Fall 2016
1. Starting OOP
Book:
Recommended: HTTP: The Definite Guide (O’REILLY, 2002)
Procedural vs. Object-Oriented
Islamabad
What is Object-Orientation?
• Architectural models
7
Example – OO Model
Islamabad
…Example – OO Model
• Objects lives-in
Ali House
9
Object-Orientation -
Advantages
• People think in terms of objects
10
What is an Object?
An object is
11
… What is an Object?
An object has
12
Example – Ali is a Tangible Object
• State (attributes)
13
Example – Car is a Tangible Object
• State (attributes)
14
Example – Time is an Object
Apprehended Intellectually
• State (attributes)
15
Example – Date is an Object
Apprehended Intellectually
• State (attributes)
16
Definition
• What Is an Object?
18
Software objects are modeled after real-
world objects
• A software object maintains its state in one or more variables .
21
Moving to new thinking …
• C programming cannot do the following well:
22
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
23
Moving to new thinking …
• A real world object, e.g. car:
• Test drive! Right?
24
Object Oriented Approach …
• Neither data nor functions, by themselves, model real-world
objects effectively.
26
Abstraction
• Principle of abstraction:
27
Example – Abstraction
Ali is a PhD student and teaches BS
• Attributes
29
Example – Abstraction
Student’s Perspective
31
Example – Abstraction
Teacher’s Perspective
33
Example – Abstraction
A cat can be viewed with different
Driver’s View
35
Abstraction – Advantages
36
Classes
37
Example – Class
• Ali studies mathematics
38
Example – Class
• Ahsan teaches mathematics
39
Graphical Representation of Classes
Suppressed
(operations)
Form
Normal Form 40
Example – Graphical Representation
of Classes
Normal Form
41
Example – Graphical Representation
of Classes
Normal Form
42
Inheritance
43
Inheritance in Classes
• If a class B inherits from class A then it contains all the
44
Example – Inheritance
45
Line
Shape
Circle
Example – Inheritance
Triangle
Islamabad
Inheritance – “IS A” or
“IS A KIND OF” Relationship
Circle Triangle
radius Line angle
49
draw length draw
computeArea draw computeArea
Inheritance – Advantages
• Less redundancy
50
Reuse with Inheritance
• Main purpose of inheritance is reuse
51
Example Reuse
Shape
color
Circle Triangle
radius Line angle
52
draw length draw
computeArea draw computeArea
Example Reuse
Person
name
Islamabad