Object Oriented Programming Lecture 01
Object Oriented Programming Lecture 01
Object
Object Oriented
Programming
Object-Oriented Programming
Mon. Tue. Wed., 9:00–10:00 a.m.
Instructor: Dr. Khalil Ullah
Email – Khalil.ullah@uom.edu.pk
Office hours – Thu. and Fri. 9:30–11:00 am.
Contact No. 03480916815.
2
Course Introduction
Required Textbook
H. M. Deitel and P. J. Deitel, C++ How to
Program, Fifth Edition. Upper Saddle
River, NJ: Prentice Hall, 2005. ISBN 0-13-
185757-6
Textbook web page:
http://www.deitel.com/books/cppHTP5/index.html
4
Some brief facts
C++ AND
OBJECT-ORIENTED PROGRAMMING
5
Historical Perspective
C++ and Object-Oriented Programming (Deitel; Randell; Wirth)
Some advantages
Easy to understand and develop because the objects
directly model real-world elements
Faster development
Easier to maintain
Object-oriented software is easier to reuse
Object-based programming
Class – program element that contains both data and
the functions that manipulate it
Object –instance of a class (like a “variable”)
Object-oriented programming
Inheritance
Polymorphism 9
Brief Facts About C++
C++ and Object-Oriented Programming (Deitel; Josuttis)
Evolved from C
Designed and implemented by Bjarne
Stroustrup at the Bell Labs in the early
1980s
“C with classes”
Standardized by ISO in 1997
Includes the C++ standard library
Standard Template Library (STL)
Part of the C++ standard library
Readymade classes for data structures and algorithms
10
C++ Features in Chapter 1
INTRODUCTION TO
C++ PROGRAMMING
11
A Simple Example Introduction to C++ Programming (Deitel)
Page 42, Fig. 2.4
C++ features
Comments
Include directive
main()
Statements end with semicolons ;
cout and << for output
std namespace
Escape characters, e.g. \n
12
1 // Fig. 2.4: fig02_04.cpp
2 // A first program in C++. Single-line
3 #include <iostream> Function main returns an comments.
4 integer value.
Left brace { beginsPreprocessor directive to
5 // function main begins program
function body. include
execution
Function input/outputStatements
main appears stream end with a
6 int main() header file <iostream>.
exactly once in every C++ semicolon ;.
7 { program..
8 std::cout << "Welcome to C++!\n";
9 Corresponding right
10 bracethat
return 0; // indicate } ends function
program ended successfully
Stream
body. Name cout insertion
belongs to operator.
11
12 } // end function main namespace std.
Keyword return is one of
Welcome to C++!
several means to exit
function; value 0 indicates
program terminated
successfully.
13
Introduction to C++ Programming (Deitel)
Another Example
15
Introduction to C++ Programming (Deitel)
18
Many of the new frameworks that are
introduced recently in the market and
are used in web development like
Object Oriented PHP and Angular
are designed using OOPs programming
concepts
OOPs concepts are very Important for a
serious programmer who want to be a
developer or a successful software
engineer in the market
19
Four main pillars of Object Oriented programming
20
Encapsulation
Look first into the procedural
programming
Program
f() x,y
f() x,y,z
f() w,x,y,z
21
Encapsulation
This problem of interdependency of
functions in procedural programing
is
f() now solved in OOPs
Property
x
Method
f()
x
22
23
Procedural programming example
float wage(float bS,int ot,float rate)
{
return bS + ot*rate;
}
int main(int argc, char** argv) {
Simpler Interface
Reduce the
impact of change
26
Inheritance
The mechanism which allows you to
eliminate the redundant code
Consider these HTML elements
HTML Element
Size
Color
Click()
Focus()
27
Polymorphism
Poly means Many and Morph means
form
It is a technique which allows you to get
28
In OOP
We implement HTML Element
Render method Size
Color
For each object and it Click()
Focus()
Will behave differently
For each object;
Virtual render(){}
In main it can be called like: textbox.render();
select.render();
29
30
We begin our introduction to object
orientation, a natural way of thinking
about the world and writing computer
programs.
Our goal here is to help you develop an
object-oriented way of thinking and to
introduce you to the Unified Modeling
Language™ (UML™)a graphical language
that allows people who design object-
oriented software systems to use an
industry-standard notation to represent
them. 31
analyze a typical requirements
document that describes a software
system (the ATM) to be built
determine the objects required to
implement that system
determine the attributes the objects will
have
determine the behaviors these objects
will exhibit
specify how the objects interact with
one another to meet the system 32
Let's begin with a simple analogy to help you reinforce your
understanding of classes and their contents.
Suppose you want to drive a car and make it go faster by pressing down
on its accelerator pedal.
What must happen before you can do this?
Well, before you can drive a car, someone has to design it and build it.
A car typically begins as engineering drawings, similar to the blueprints
used to design a house.
These drawings include the design for an accelerator pedal that the
driver will use to make the car go faster.
In a sense, the pedal "hides" the complex mechanisms that actually
make the car go faster, just as the brake pedal "hides" the mechanisms
that slow the car, the steering wheel "hides" the mechanisms that turn
the car and so on.
This enables people with little or no knowledge of how cars are
engineered to drive a car easily, simply by using the accelerator pedal,
the brake pedal, the steering wheel, the transmission shifting
mechanism and other such simple and user-friendly "interfaces" to the
car's complex internal mechanisms. 33