0% found this document useful (0 votes)
5 views

Object-Oriented-Programming

The document discusses two programming paradigms: Procedural Programming and Object-Oriented Programming (OOP). Procedural Programming focuses on procedures and functions, while OOP emphasizes data and objects, offering features like encapsulation, inheritance, and polymorphism. OOP is designed to manage complexity and improve code reusability, though it comes with its own set of advantages and disadvantages compared to procedural programming.

Uploaded by

prachansubedi4
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Object-Oriented-Programming

The document discusses two programming paradigms: Procedural Programming and Object-Oriented Programming (OOP). Procedural Programming focuses on procedures and functions, while OOP emphasizes data and objects, offering features like encapsulation, inheritance, and polymorphism. OOP is designed to manage complexity and improve code reusability, though it comes with its own set of advantages and disadvantages compared to procedural programming.

Uploaded by

prachansubedi4
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

Procedural Programming Language:

Procedural Programming is a programming paradigm that uses a linear or top-down approach.


Procedural programming divides the program into procedures, routines or functions which
contains a series of steps to be carried out. Some of the examples of procedural programming
paradigm are C, COBOL, FORTRAN, BASIC,etc.
Advantages:
i) The program flow can be tracked easily as it flows in linear direction.
ii) The same block of code can be called and reused in different parts of the program.
iii) It simplifies the code and makes it easy to understand.
iv) It consumes less memory space on the computer.
v) It is regarded best for general programming to learn and implement.
Disadvantages :
i) The priority is given to function rather than the data, which might pose issues in some
data sensitive cases.
ii) It is difficult to relate with real-world objects and not very practical with a real world
problem.
iii) The data is exposed to the whole program and lack security.
iv) Maintaining and enhancing program code is still difficult.

Object Oriented Programming (OOP)


Object oriented programming is a programming paradigm that was developed to overcome the
drawbacks and limitations of particularly procedure oriented programming. The major need for
developing such languages was to manage the ever-increasing size and complexity of programs.

Object-oriented programming (OOP) is a computer programming model that organizes software


design around data, or objects, rather than functions and logic. An object can be defined as a data
field that has unique attributes and behavior.

Some of e.g. of OOP C++, Java, JavaScript, PHP, C#, VB.Net, etc.

Features/Characteristics of OOP
a) Emphasis is on data rather than procedure.
b) Programs are divided into objects.
c) Data structures are designed such that they characterize the objects.
d) Functions that separate on the data of an object are tied together in the data structure.
e) Data is hidden and cannot be accessed by external functions.
f) Objects may communicate with each other through functions.
g) New data and functions can be easily added whenever necessary.
h) Bottom-up approach is followed in program design.

Advantages of OOP:
a) We can eliminate redundant codes by using inheritance feature of OOP.
b) It is very easy for managing complex and large size problems.
c) The most important is the reusability of codes by using the features inheritance.
d) It takes very less time for the development and maintaining the software.
e) It is efficient for testing and implementation of the system.

OOP has several disadvantages which made it unpopular in the early years.
a) Size: Object oriented programs are much larger than other programs. In the early days of
computing, space on hard drives, floppy drives and in memory was at a premium. Today
we do not have these restrictions.
b) Effort: Object oriented programs require a lot of work to create. Specifically, a great deal
of planning goes into an object oriented program well before a single piece of code is
ever written. Initially, this early effort was felt by many to be a waste of time. In addition,
because the programs were larger coders spent more time actually writing the program.
c) Speed: Object oriented programs are slower than other programs, partially because of
their size. Other aspects of Object Oriented Programs also demand more system
resources.

Features of OOP
Object: An object is any entity, thing or organization that exits in real world. It consists of two
fundamentals characteristics: its attributes and behaviors. For example: a dog is an object having
attributes such as color, weight, age, etc. and behaviors such as barking, wagging tail, etc. In
OOP, attributes are represented by data and behaviors are represented by functions.

Class: A class is the collection of similar objects. It is defined as the template or prototype to
define the common attributes and behavior for all the objects of the class. The entire set of data
and code of an object can be made a user-defined data type with the help of a class. In fact
objects are variables of type class. Once, a class has been defined, we can create any number of
objects associated with that class.
Real life Example of Class and object

Consider an ATM. An ATM is a class. It’s machine which is pretty much useless until you insert
your debit card. After you insert your debit card, the machine has information about you and
your bank account and the balance in it, so at this point it is an object. You have used a class and
created an object, now you can perform operations on it like withdrawal of money or checking
you balance or getting statement of your account, these operations will be methods belonging to
that class (ATM) but you cannot use them until you create an object out of it.

And when you did perform whatever operation you wanted to perform and clicked exit/cancel
and removed your card, you just destroyed the object. Now it is not an object, it has methods and
all (the functions an ATM can perform) but you cannot use them until you insert your card again
and create an object.

What are Classes and Objects?

Classes and objects are the two main aspects of object-oriented programming.

Look at the following illustration to see the difference between class and objects:

Class objects

Fruit Apple

Banana

Mango

Another example:

Class objects

Car Volvo

Audi

Toyota

So, a class is a template for objects, and an object is an instance of a class.

When the individual objects are created, they inherit all the variables and functions from the
class.

Data abstraction: It is a collection of data and methods. In OOP, data abstraction defines the
conceptual boundaries of an object. These boundaries distinguish an object from another object.
So, abstraction is the act of representing essential features without including the background
details. It focuses the outside view of an object, separating its essential behavior from its
implementation.

Encapsulation: Encapsulation is a way of organizing data and function into a structure by


concealing the way the object is implemented, that is preventing access to data by any means
other than those specified. Encapsulation therefore guarantees the integrity of the data contained
in the object. It implies that there is visibility to the functionalities offered by an object, and no
visibility to its data.

Data encapsulation is the mechanism that binds code and data it manipulates and keeps both safe
from outside interference and misuse. The data are visible only to that particular function, called
data hiding.

Polymorphism : The word "Polymorphism" is derived from Greek word "Poly-morphos" which
means many forms. The different ways of using same function or operator depending on what
they are operating on is called polymorphism. In OOP, polymorphism refers to a programming
language's ability to process objects differently depending on their data type or class.
For eg an operator symbol '+' which is used for arithmetic operation among two numbers,
but by overloading we use it for complex object like time that has hr, minutes and second as its
attributes. By overloading, same operator '+' we can also perform that string concatenation.

Inheritance : Inheritance is the process by which objects of one class acquire the properties of
objects of another class. For e.g, all vehicles in a class may share similar properties of having
wheels and a motor.
Inheritance is a way to form new classes(instance of which are called objects)
Types of Inheritance :
a) single inheritance : In this inheritance, there is a derived class with only one base class.
i.e if a child class is built from only one parent class.
b) Multi Inheritance : In this inheritance, the derived class has several base classes. If a child
class is built from two or more than two parents classes.
c) Hierarchical Inheritance : In this inheritance, the behavior of one class may be derived by
more than one class.
d) Multiple Inheritance : In this inheritance, the mechanism of deriving a class from another
derived class.
Inheritance and polymorphism important feature in OOP
The process of creating a new class form an existing class in which objects of the new class
inherit the attributes and behaviors of the existing class is known as inheritance. The newly
created class is called derived class or child class and the class from which new class is derived
is called base class or parent class. It permits the expansion and reuse of existing code without
rewriting it hence, the concept of inheritance supports the concept of reusability.
The meaning of polymorphism is having many forms. It is an important feature of OOP which
refers to the ability of an object to take on different forms depending upon situations. It
simplifies coding and reduces the rework involved in modifying and developing an application.

What is OOP?

OOP stands for Object-Oriented Programming.

Procedural programming is about writing procedures or functions that perform operations on the
data, while object-oriented programming is about creating objects that contain both data and
functions.

Object-oriented programming has several advantages over procedural programming:

 OOP is faster and easier to execute


 OOP provides a clear structure for the programs
 OOP helps to keep the C++ code DRY "Don't Repeat Yourself", and makes the code
easier to maintain, modify and debug
 OOP makes it possible to create full reusable applications with less code and shorter
development time
OOP Concepts with real-world examples

What is OOP?

OOP - Object-Oriented Programming is a programming paradigm that is based on objects.

(Objects - real-world entities like book, vehicle, tree, etc..)

Now let's see what are OOP concepts.


There are 4 OOP concepts. They are,

1. Polymorphism

2. Inheritance

3. Encapsulation

4. Abstraction

1. Polymorphism

Polymorphism is the ability to exist in many forms.

Example 1: We can take a boy as a real-world example. This boy can be a student, a player, and a

writer. So that this boy can exist in different ways in different situations.

Example 2: Sound of animals. People have the same sound but different animals make different

sounds. The following diagram shows few different sounds make by animals.
This what we called as polymorphism.

2. Inheritance

Inheritance means it allows classes to inherit common properties from the parent class.

Example 1: let's assume that there is a class as Vehicle. All vehicles are not the same. We can

inherit common properties like color, size, type from the parent vehicle class and create classes
like Car, Bus, Bike.
Example 2: let's take another parent class as Animals. Here also we can inherit common

properties like name, sound, color, breed from Animal class and create classes like Dog, Cat,

Horse and etc.

3. Encapsulation

Encapsulation means it binds data and code together into one unit.

Example1; the most commonly used example is the medical capsule. This capsule mixes few

types of medicines and stored in one capsule.


Example 2: another example for encapsulation is a large organization. An organization is consists

of several departments like the production department, purchase department, sales department,

and Accounts department. It combines all these departments together and had formed the

organization.

This is what we called as encapsulation.

4. Abstraction

In abstraction, it displays only the important information by hiding the implementation part.

Example 1: Let's take the ATM machine. In an ATM machine, we can perform functions like

withdraw cash, deposit cash, check balance, print bills, and so on. Even though it performs a lot of

actions it doesn’t show us the process. It has hidden its process by showing only the main things

like getting inputs and giving the output.


Example 2: The next example is the most commonly used mobile phones. On a mobile phone, we

can perform so many actions like making a call, sending messages, take pictures, download

software and etc. We perform a lot of things but here also we don't know the inside process of

these things. Which means the implementation parts are hidden.

This is what we called as an abstraction.

You might also like