Object Oriented Programming
Lecture 1
Instructor Name: Engr. Farhan Ghafoor
Evaluation of Object
Oriented Pro-
gramming (OOP)
Contents
The study of programming languages
Introduction to programming paradigm
Programming Language types
Unstructured programming languages
Procedural programming languages
Structured programming languages
Object Oriented programming (OOP) languages
Building blocks of OOP
Why OOP?
Features of OOP
References
Next lecture topics
The study of programming languages
The purpose of language is simply that it must convey meaning.
Whatever can be said, can be said clearly.
A programming language is a notation for writing programs.
A computer program is a collection of instructions that can be
executed by a computer to perform a specific task. A computer
program is usually written by a computer programmer in a
programming language.
Introduction of paradigm and programming paradigms
o Paradigm can also be termed as method to solve some
problem or do some task.
o Programming paradigm is an approach to solve problem
using some programming language.
o Also we can say it is a method to solve a problem using
tools and techniques that are available.
Introduction of paradigm and programming paradigms
o There are lots for
programming language
that are known but all of
them need to follow some
strategy when they are
implemented and this
methodology/strategy is
paradigms.
Programming Languages
• Machine language
• Unstructured programming languages
• Procedural programming languages
• Structured oriented programming languages
• Object oriented programming languages
Procedural
Structured Object
Unstructured programming
programming oriented
Machine programming languages
languages programming
Language languages e.g.
e.g. C and languages
e.g. assembly FORTRAN,
PASCAL e.g. C++ JAVA
COBOL
Overview of programming language types and levels
Machine language
• Machine language is the language understood by a
computer.
• Very difficult to understand, but it is the only thing that
the computer can work with.
• All programs and programming languages eventually
generate or run programs in machine language.
Machine language
Machine code, consisting of machine language
instructions, is a low-level programming language used to
directly control a computer's central processing unit (CPU).
Machine language can only be represented by 0s and 1s.
Assembly language
Assembly language is the more than low level and less
than high-level language so it is intermediary language.
Assembly languages use numbers, symbols, and
abbreviations instead of 0s and 1s.
Machine language vs Assembly language
Machine Language Assembly Language
Assembly language is only understand by human beings
Machine language is only understand by the computers.
not by the computers.
In machine language data only represented with the help of In assembly language data can be represented with the
binary format(0s and 1s), hexadecimal and octadecimal. help of mnemonics such as Mov, Add, Sub, End etc.
Machine language is very difficult to understand by the hu- Assembly language is easy to understand by the human be-
man beings. ing as compare to machine language.
Modifications and error fixing cannot be done in machine Modifications and error fixing can be done in assembly lan-
language. guage.
Machine language is very difficult to memorize so it is not Easy to memorize the assembly language because some
possible to learn the machine language. alphabets and mnemonics are used.
Execution is fast in machine language because all data is
Execution is slow as compared to machine language.
already present in binary format.
There is no need of translator.The machine understandable Assembler is used as translator to convert mnemonics into
form is the machine language. machine understandable form.
Assembly language is the machine dependent and it is not
Machine language is hardware dependent.
portable.
Unstructured programming languages
Entire logic of the program is written as a single continuous (nonstop
or unbroken) block is called "unstructured Programming".
Consists of just writing the sequence of commands or statements in
the main program.
Program written by following this language is very difficult to modify
and to debug.
Example, assembly language programs.
Unstructured programming languages
Limitations
Data is global and code operate on it.
The concept of local variable did not exist.
Does not have independent data for processing.
As the code increases, maintenance become more complex.
Reusability of code not supported.
Procedural programming languages
The first programming paradigm that a new developer will
learn.
Fundamentally, the procedural code is the one that directly
instructs a device on how to finish a task in logical steps.
This paradigm uses a linear top-down approach and treats
data and procedures as two different entities.
Example FORTRAN and COBOL language programs.
Procedural programming languages
Procedural programming divides the program into
procedures, which are also known as routines or functions,
simply containing a series of steps to be carried out.
It involves writing down a list of instructions to tell the
computer what it should do step-by-step to finish the task at
hand.
Program flow control is achieved through function calls and
goto statements.
Procedural oriented programming languages
The program code is harder to write.
The procedural code is often not reusable, need to recreate.
Limitations
Difficult to relate with real-world objects.
The importance is given to the operation rather than the data, which
might pose issues in some data-sensitive cases.
Data is not secured because data is global and can be accessed by
any function.
Structured programming languages
Large programs are divided into small programs called
functions, modules, subprogram, subroutines and procedures.
Modular programming is another name for this.
These functions have statements embraced inside curly
braces. Each function is design to do a specific task with its
own data and logic.
Data moves freely around the systems from one function to
another.
Structured programming languages
Information can be passed from one function to another
function through parameters.
A function can have local data that cannot be accessed
outside the function’s scope.
Easier for the programmer to test and debug the code
Program structure follows “Top Down Approach”. Example:
C, Pascal, ALGOL and Modula-2
Structured oriented programming languages
Limitations
Data hiding
Debugging of program is hard
Not possible to handle run time errors and future
enhancements
Software development period and cost is high
If end user require changes, a big modification is
needed in software
More stress laid on procedures not on data
Object oriented programming languages
OOP is a fundamental programming paradigm
In this type of language, programs are divided into objects.
Prime focus is on the data that is being operated and not on the
functions or procedures.
Data is hidden and cannot be accessed by external functions.
Program structure follows “Bottom UP Approach”.
Object oriented programming languages
The focus of OOP languages is not on structure, but
on modeling data.
The main aim of OOP is to bind together the data
and the functions that operate on them so that no
other part of the code can access this data except
that function.
Object oriented programming languages
OOP is a programming paradigm that relies on the
concept of classes and objects.
It is used to structure a software program into simple,
reusable pieces of code blueprints (usually called
classes) which are used to create individual instances
of objects.
Object oriented programming languages
A programmer designs a software program by
organizing related pieces of information and behaviors
together into a template called a class
The entire software program runs by having multiple
objects interact with objects to create the larger
program
Examples of OOP languages include C++, Visual
Basic.NET and Java.
Comparison
Procedure/Structure oriented
Object oriented
Bottom-up.
Top-down.
Main focus is on 'data security'. Hence, only ob-
Main focus is on "how to get the task done" i.e. on jects are permitted to access the entities of a
the procedure or structure of a program . class.
Large program is divided into units called func-
Entire program is divided into objects.
tions.
Access specifier are "public", "private",
No access specifier observed.
"protected".
It overloads functions, constructors, and operators.
Neither it overload functions nor operators.
Comparison
Procedure/Structure oriented
Object oriented
Inheritance achieved in three modes public private and
Their is no provision of inheritance. protected.
There is no proper way of hiding the data, so data Data is hidden in three modes public, private, and pro-
is insecure tected. hence data security increases.
Data is shared among the objects through the member
Global data is shared among the functions in the
functions.
program.
Classes or function can become a friend of another
class with the keyword "friend".
No concept of friend function.
Note: "friend" keyword is used only in c++
Concept of virtual function appear during inheritance.
No concept of virtual classes .
Building blocks of OOP
The code building blocks to build an OOP program are:
Classes (Blue print/prototype)
A class is a user defined blueprint or prototype from which
objects are created. It represents the set of properties or
methods that are common to all objects of one type.
Building blocks of OOP
Objects (Instance of class)
Usually a person, place or thing (a noun). An object is an
instance of class. objects stores data and provides method
for accessing and modifying this data.
Object is considered to be partitioned area of compute
memory that stores data and a set of operations that can
access the data
Building blocks of OOP
Methods (Behavior / actions)
Are function that manipulate the data, an action
performed by an object (a verb)
Attributes
(instance variable / information / property / characteristic / field
and state) are the attributes of the object, - Characteristics of
certain object.
Example
Why OOP?
OOP is an approach that provides a way of
modularizing programs by creating partitioned memory
area for both data and functions that can be used as
templates for creating copies of such modules on
demand.
OOP makes code organized, reusable, and easy to
maintain. It follows the DRY (Don’t Repeat Yourself)
principle used by many programmers to make efficient
programs
Why OOP?
OOP also prevents unwanted access to data, or
exposing proprietary code through encapsulation and
abstraction. Both are discussed later
So how do programmers create Object Oriented
programs? Well the short answer is by making classes,
and creating objects from the classes. Classes form the
blueprint for how data & behaviors are structured.
Why OOP?
Objects are created for specific instances of a class. As
a programmer, you might create a dog class (blueprint)
as a standard way to organize all the important
information about dogs, and then instantiate an
individual dog as an object created from the dog class -
like your dog xyz.
Features of OOP
34
References
• https://www.geeksforgeeks.org/classes-objects-java/
• https://
techdifferences.com/difference-between-oop-and-pop.html
• https://www.educative.io/blog/object-oriented-programming
• https://www.geeksforgeeks.org/difference-between-machine
-language-and-assembly-language
/
• https://www.learncomputerscienceonline.com/computer-pro
gramming/#
POST2anchor2
• https://www.geeksforgeeks.org/introduction-of-programming
-paradigms
36
THANK YOU
37
Next
Introduction to Java, NetBeans IDE, basic
program, syntax, first program with use of
class, object, attribute and method