0% found this document useful (0 votes)
151 views8 pages

2 - POP - OOP - OOPs Concepts

The document discusses procedural programming versus object-oriented programming. Procedural programming focuses on functions and uses global data, while object-oriented programming treats data as critical elements and ties data closely to functions. The document also outlines the basic elements of object-oriented programming including objects, classes, data abstraction, encapsulation, inheritance, polymorphism, and dynamic binding.

Uploaded by

Disha Nayak
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
151 views8 pages

2 - POP - OOP - OOPs Concepts

The document discusses procedural programming versus object-oriented programming. Procedural programming focuses on functions and uses global data, while object-oriented programming treats data as critical elements and ties data closely to functions. The document also outlines the basic elements of object-oriented programming including objects, classes, data abstraction, encapsulation, inheritance, polymorphism, and dynamic binding.

Uploaded by

Disha Nayak
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

PROGRAMMING APPROACH

Procedure Oriented Programming

⮚ A program in a procedural language is a list of instructions where each statement tells the computer
to do something.
⮚ It focuses on procedure (function).
⮚ When a program becomes larger, it is divided into functions & each function has a clearly defined
purpose.
⮚ Most of the functions share global data.
⮚ Global data is accessible by all functions.
⮚ Global data is more unsafe to an accidental change by a function because if a function makes any
changes to global data, these changes will reflect in other functions.
⮚ Each function may have its own local data.
⮚ Procedure oriented Programming follows Top Down Approach in problem solving.

(Structure of Procedure Oriented Programming)

⮚ Example of POP Languages are: BASIC, COBOL, FORTRAN and C

Drawback of Procedural oriented programming:-

⮚ It emphasizes doing things. Data is given a second class status even though data is the reason for
the existence of the program.
⮚ Since every function has complete access to the global variables, the new programmer can corrupt
the data accidentally by creating a function. Similarly, if new data is to be added, all the functions
need to be modified to access the data.
⮚ It is often difficult to design because the components function and data structure do not model the
real world.
Object Oriented Programming

⮚ The major motivating factor in the invention of object-oriented approach is to remove some of the
drawbacks encountered in the procedural approach.
⮚ OOP treats data as a critical element in the program development and does not allow it to flow
freely around the systems.
⮚ It ties data more closely to the functions that operate on it, and protects it from accidental
modification from outside functions.
⮚ OOP allows decomposition of a problem into a number of entities called objects and then builds
data and functions around these objects.
⮚ The data of an object can be accessed only by the function associated with that object.
⮚ Data is hidden and cannot be accessed by external functions.
⮚ However, functions of one object can access functions of other objects.
⮚ OOP Follows bottom-up approach in program design.

(Structure of Object Oriented Programming)

⮚ Example of OOP Languages are: C++, JAVA, PYTHON, C# etc

Difference between Procedural Programming and Object Oriented Programming:

PROCEDURAL ORIENTED PROGRAMMING OBJECT ORIENTED PROGRAMMING

In procedural programming, program is divided


In object oriented programming, program is
into small parts called functions.
divided into small parts called objects.
Procedural programming follows top down
Object oriented programming follows bottom up
approach.
approach.
There is no access specifier in procedural
Object oriented programming have access
programming.
specifiers like private, public, protected etc.
Adding new data and functions is not easy.
Adding new data and functions is easy.
Procedural programming does not have any
Object oriented programming provides data
proper way for hiding data so it is less secure.
hiding so it is more secure.
In procedural programming, overloading is not
Overloading is possible in object oriented
possible.
programming.
In procedural programming, function is more
In object oriented programming, data is more
important than data.
important than function.
Procedural programming is based on unreal
Object oriented programming is based on real
world.
world.
EXAMPLES: C, FORTRAN, PASCAL, BASIC
EXAMPLES: C++, JAVA, PYTHON, C# etc.
etc.
BASIC ELEMENTS OF OBJECT ORIENTED PROGRAMMING

⮚ Object Oriented Programming has the following basic and necessary concepts such as:
❖ Object
❖ Class
❖ Data Abstraction
❖ Encapsulation
❖ Data Hiding
❖ Inheritance
❖ Polymorphism
❖ Dynamic Binding

1. Object
⮚ Any real world entity that has state and behavior is known
as an object. For example, a chair, pen, table, keyboard,
bike, etc.
⮚ It can be physical or logical.
⮚ In OOP, an Object can be defined as an instance of a class.
⮚ Objects are also referred to as the basic runtime entity
because during execution of the program objects are
essential.
⮚ An object contains an address and takes up some space in
memory.
⮚ Objects can communicate without knowing the details of each other's data or code.
⮚ The only necessary thing is the type of message accepted and the type of response returned
by the objects.
⮚ Different objects have different states or characteristics and behaviour.
⮚ In OOP, the states or characteristics of an object is referred as member variable or data
members which is used to hold data
⮚ The behaviour of an object can be implemented through member functions or methods.

Example:
Real world object (Book)
State or characteristics Behaviour
Chapters Used to read
Pages Used to prepare notes
Topics
OOP programming object(Student)

Data Members Member Functions/Methods

Name Acceptdata()
Class Display()
Marks
2. Class
⮚ Class is a group of similar types of objects, which possess some attributes and behaviour.
⮚ It describes the nature of an object.
⮚ Example: If we consider Fruits as a class then apple, orange, mango, banana are considered
as objects of the class Fruits.
⮚ We can create a class within another class also for some application (if required).
⮚ Class are considered as user defined datatypes whereas objects can be considered as
variables of the class.
⮚ Example: If Automobile is considered as a class then TwoWheeler, ThreeWheeler and
FourWheeler are considered as the subc-classes of the class Automobile.
⮚ In OOP, both class and objects are dependent on each other or in other words they are
considered as two sides of a coin.
Attributes of a Class:
⮚ Every object has some characteristics and behaviour.
⮚ The characteristics of an object are called data members and the behavior are called
member methods or member functions or simply methods in a class.
⮚ These data members and member functions are called as attributes of the class.
⮚ Example:
Class Student: Attributes

Data Members Member Functions


(Methods)

Name Getdata( )

Roll_Number Dispdata( )

Class

Section

Contact_Number
Mail_id

Creating objects from a class:


⮚ In OOP once a class is defined any number of objects can be created from the class.
⮚ Class does not occupy any memory, whereas objects occupy space in memory.
⮚ In java, the new keyword is used for allocating memory for an object dynamically.
⮚ Once memory is allocated the data members and member functions belonging to the object
are placed in that occupied memory.
⮚ Different steps involved for creating object are:
● Declaration: Fruit apple; (Fruit is the class and apple is the object)
● Instantiation: Fruit apple = new Fruit(); (Reserves memory for the object apple)
● Initialization: To provide initial value to the data members of an object through
constructor.
3. Data Abstraction
⮚ Representing essential features and hiding background details is known as Data
Abstraction.
Example: Two ride a two-wheeler we should know about the accelerator, break, horn,
clutch, gear etc but not essentially how the engine works.
⮚ It is the absolute property of the class.
⮚ Since a class uses the property of abstraction, it is also called an abstract data type.
⮚ In java, abstraction is achieved by interfaces and abstract classes.

4. Encapsulation
⮚ In OOP data are not allowed to move freely from functions to functions
hence are kept securely inside a class.
⮚ Data are allowed to be accessed by the member functions of that class.
⮚ Hence, it is necessary to bind the data members and member functions
into a single unit.
⮚ Binding (or wrapping) of the data members and member functions into a single unit is
known as Data Encapsulation.
⮚ As a medicine capsule is wrapped with different medicines.

5. Data Hiding
⮚ The insulation of data from the outside world by using the concept of Encapsulation is
called Data hiding.
6. Inheritance
⮚ The process of creating a new class from the existing class is called Inheritance.
⮚ The existing class is called the base class.
⮚ The newly created class from the base class is called a derived class.
⮚ The derived class can acquire all the properties of the base class.
⮚ Code reusability is one of the benefits of inheritance.
⮚ Code Reusability means the codes or the implementation procedures of the base class can
be used in the derived class (No need to rewrite the code).
⮚ There are five different types of inheritances such as
● Single Inheritance
● Multilevel Inheritance
● Multiple Inheritance (Java does not support directly)
● Hierarchical Inheritance
● Hybrid Inheritance

7. Polymorphism
⮚ Poly means many and morphos means forms. Hence, polymorphism means many forms.
⮚ It describes the feature of languages that allows the same word or symbol to be interpreted
correctly in different situations based on the context.
Example:
In java when the symbol ‘+’ used with numbers performs addition operation and when used
with strings performs concatenation operation.
10 + 20 = 30
“comp” + “uter” = “computer”
⮚ There are two types of Polymorphism available in Java.
● Static polymorphism: It is otherwise called compile time polymorphism.
Example: Method Overloading
● Dynamic polymorphism: It is otherwise called as Runtime polymorphism
Example: Method Overriding
8. Dynamic Binding
⮚ It is the link that is established between the Method call and Method signature
⮚ Dynamic binding also called dynamic dispatch
⮚ It is the process of linking procedure calls to a specific sequence of code (method) at run-
time.
⮚ The compiler generates a coded address of the function signature and applies it at the
function call position in the caller program.
⮚ The control gets transferred to the address available at the function call position, at the time
of execution. This process is called dynamic binding

⮚ The compiler generates the machine code address of the function calculate() say 10101
which is placed in the caller program at call position.

⮚ On executing the caller, program control gets transferred in the required address to invoke
the calculate() function.

== x ==

You might also like