Lecture One

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 14

COS 113: INTRODUCTION TO OBJECT ORIENTED PROGRAMMING

LECTURE ONE: PARADIGMS OF PROGRAMMING

Programming paradigms are different ways or styles in which a given program or programming language can be
organized. Each paradigm consists of certain structures, features, and opinions about how common programming
problems should be tackled.

Paradigm can also be termed as method to solve some problem or do some tasks. Programming paradigm is an
approach to solve problem using some programming language or also we can say it is a method to solve a problem
using tools and techniques that are available to us following some approach. 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. Apart from varieties of programming language there are lots of paradigms to
fulfill each and every demand.

The question of why are there many different programming paradigms is similar to why are there many
programming languages. Certain paradigms are better suited for certain types of problems, so it makes sense to
use different paradigms for different kinds of projects.

Also, the practices that make up each paradigm have developed through time. This is due to the advances both in
software and hardware, different approaches have come up that did not exist before.

And finally, there is human creativity. As a species, Humans just like creating things, improving what others have
built in the past, and adapting tools to their preference or to what seems more efficient for them.

All this results in the fact that today we have many options to choose from when we want to write and structure a
given program.

Programming paradigms are not languages or tools. You can't "build" anything with a paradigm. They are more like
a set of ideals and guidelines that many people have agreed on, followed, and expanded upon.

Programming languages are not always tied to a specific paradigm. There are languages that have been built or
designed with a certain paradigm in mind and have features that facilitate that kind of programming more than
others (Haskel and functional programming is a good example) but there are also "multi-paradigm" languages,
meaning you can adapt codes to fit a certain paradigm or another (JavaScript and Python are good examples).

At the same time, programming paradigms are not mutually exclusive, in the sense that you could use practices
from different paradigms at the same time with no problem at all.

It is interesting to understand the many ways in which programming can be done. Moreover, these terms are used
a lot in the coding world, so having a basic understanding will help you better understand other topics as well.

TYPES OF PROGRAMMING PARADIGMS

IMPERATIVE PROGRAMMING

1.Imperative programming consists of sets of detailed instructions that are given to the computer to execute in a
given order. It's called "imperative" because as programmers we dictate exactly what the computer has to do, in a
very specific way. Imperative programming focuses on describing how a program operates, step by step.
It is one of the oldest programming paradigms. It features close relation to machine architecture. It is based on Von
Neumann architecture. It works by changing the program state through assignment statements. It performs step
by step task by changing state. The main focus is on how to achieve the goal. The paradigm consists of several
statements and after execution of all the result is stored.

Say you want to bake a cake. Your imperative program to do this might look like this

1- Pour flour in a bowl


2- Pour a couple eggs in the same bowl
3- Pour some milk in the same bowl
4- Mix the ingredients
5- Pour the mix in a mold
6- Cook for 35 minutes
7- Let chill
Using an actual code example, let's say we want to filter an array of numbers to only keep the elements bigger
than 5. Our imperative code might look like this in JavaScript:

const nums = [1,4,3,6,7,8,9,2]


const result = []
for (let i = 0; i < nums.length; i++) {
if (nums[i] > 5) result.push(nums[i])
}
console.log(result) // Output: [ 6, 7, 8, 9]
See that we are telling the program to iterate through each element in the array, compare the item value with 5,
and if the item is bigger than 5, push it into an array. We are being detailed and specific in our instructions, and
that's what imperative programming stands for.

Advantages of the Imperative Paradigm of Programming


a) Very simple to implement
b) It contains loops, variables etc.

Disadvantage of the Imperative Paradigm of Programming


a) Complex problem cannot be solved
b) Less efficient and less productive
c) Parallel programming is not possible

Examples of programming language suitable for Imperative programming paradigm:


C : developed by Dennis Ritchie and Ken Thompson
Fortran : developed by John Backus for IBM
Basic : developed by John G Kemeny and Thomas E Kurtz

Example of the imperative Programming in python3


def main():
# Array to store marks
marks = [12, 32, 45, 13, 19]

# Variable to store the sum of marks


total_marks = sum(marks)

# Calculate the average


average = total_marks / len(marks)

# Output the average


print("Average of five numbers:", average)

if __name__ == "__main__":
main()

Output
Average of five numbers: 24.2
Imperative programming is divided into three broad categories: Procedural, Object Oriented Programing and
parallel processing. These paradigms are as explained below

a.Procedural Programming: Procedural programming is a derivation of imperative programming, adding to it the


feature of functions (also known as "procedures" or "subroutines"). In procedural programming, the user is
encouraged to subdivide the program execution into functions, as a way of improving modularity and
organization.

Following the cake example, procedural programming may look like this:
function pourIngredients() {
- Pour flour in a bowl
- Pour a couple eggs in the same bowl
- Pour some milk in the same bowl
}
function mixAndTransferToMold() {
- Mix the ingredients
- Pour the mix in a mold
}
function cookAndLetChill() {
- Cook for 35 minutes
- Let chill
}
pourIngredients()
mixAndTransferToMold()
cookAndLetChill()
You can see that, thanks to the implementation of functions, we could just read the three function calls at the end
of the file and get a good idea of what our program does. The simplification and abstraction is one of the benefits
of procedural programming but within the functions, we still have the same old imperative programming paradigm
codes.

Examples of programming Language suitable for Procedural programming paradigm:


C : developed by Dennis Ritchie and Ken Thompson
C++ : developed by Bjarne Stroustrup
Java : developed by James Gosling at Sun Microsystems
ColdFusion : developed by J J Allaire
Pascal : developed by Niklaus Wirth
Example of the procedural programming paradigm in python 3

# Prompt user to enter a number


num = int(input("Enter any Number: "))

fact = 1 # Initialize factorial variable

# Calculate factorial
for i in range(1, num + 1):
fact = fact * i

# Print the factorial


print("Factorial of", num, "is:", fact)
b.Object oriented programming: One of the most popular programming paradigms is object-oriented programming
(OOP). The core concept of OOP is to separate concerns into entities which are coded as objects. Each entity will
group a given set of information (properties) and actions (methods) that can be performed by the entity. OOP
makes heavy usage of classes (which are a way of creating new objects starting out from a blueprint or boilerplate
that the programmer sets). Objects that are created from a class are called instances.

The program is written as a collection of classes and object which are meant for communication. The smallest and
basic entity is object and all kind of computation is performed on the objects only. More emphasis is on data rather
procedure. It can handle almost all kind of real-life problems which are today in scenario.

Following our pseudo-code cooking example, now let's say in our bakery we have a main cook (called Frank) and an
assistant cook (called Anthony) and each of them will have certain responsibilities in the baking process. If we used
OOP, our program might look like this.

// Create the two classes corresponding to each entity


class Cook {
constructor constructor (name) {
this.name = name
}

mixAndBake() {
- Mix the ingredients
- Pour the mix in a mold
- Cook for 35 minutes
}
}

class AssistantCook {
constructor (name) {
this.name = name
}

pourIngredients() {
- Pour flour in a bowl
- Pour a couple eggs in the same bowl
- Pour some milk in the same bowl
}

chillTheCake() {
- Let chill
}
}

// Instantiate an object from each class


const Frank = new Cook('Frank')
const Anthony = new AssistantCook('Anthony')

// Call the corresponding methods from each instance


Anthony.pourIngredients()
Frank.mixAndBake()
Anthony.chillTheCake()
The nice thing about OOP is that it facilitates the understanding of a program, by the clear separation of concerns
and responsibilities.

Advantages of the Object-Oriented Programming


a) Data security
b) Inheritance
c) Code reusability
d) Flexible and abstraction is also present

Examples of Programming Languages suitable for the Object-Oriented programming paradigm:


Simula: first OOP language
Java: developed by James Gosling at Sun Microsystems
C++: developed by Bjarne Stroustrup
Objective-C: designed by Brad Cox
Visual Basic .NET: developed by Microsoft
Python: developed by Guido van Rossum
Ruby: developed by Yukihiro Matsumoto
Smalltalk: developed by Alan Kay, Dan Ingalls, Adele Goldberg

Example of the OOP in Python 3


class Signup:
def __init__(self):
self.userid = 0
self.name = ""
self.emailid = ""
self.sex = ""
self.mob = 0

def create (self, userid, name, emailid, sex, mob):


print("Welcome to Object-Oriented Programming Class\nLets create your account\n")
self.userid = 132
self.name = "Rukky"
self.emailid = "Rukky.89@gmail.com"
self.sex = 'F'
self.mob = 900558981
print("your account has been created")

if __name__ == "__main__":
print("OOP Class!")
s1 = Signup()
s1.create(22, "riya", "riya2@gmail.com", 'F', 89002)
Output
OOP Class!
Welcome to Object-Oriented Programming Class
your account has been created
Difference between Procedural Oriented Programming and Object-Oriented Programming
Procedural Oriented Programming Object-Oriented Programming
In procedural programming, the program is divided into In object-oriented programming, the program is
small parts called functions. divided into small parts called objects.
Procedural programming follows a top-down approach. Object-oriented programming follows a bottom-up
approach.
There is no access specifier in procedural programming. Object-oriented programming has access specifiers
like private, public, protected, etc.
Adding new data and functions is not easy. Adding new data and function is easy.
Procedural programming does not have any proper way Object-oriented programming provides data hiding so
of hiding data so it is less secure. it is more secure.
In procedural programming, overloading is not possible. Overloading is possible in object-oriented
programming.
In procedural programming, there is no concept of data In object-oriented programming, the concept of data
hiding and inheritance. hiding and inheritance is used.
In procedural programming, the function is more In object-oriented programming, data is more
important than the data. important than function.
Procedural programming is based on the unreal world. Object-oriented programming is based on the real
world.
Procedural programming is used for designing medium- Object-oriented programming is used for designing
sized programs. large and complex programs.
Procedural programming uses the concept of procedure Object-oriented programming uses the concept of
abstraction. data abstraction.
Code reusability absent in procedural programming, Code reusability present in object-oriented
programming.
Examples: C, FORTRAN, Pascal, Basic, etc. Examples: C++, Java, Python, C#, etc.

c. Parallel Processing Approach: Parallel processing is the processing of program instructions by dividing them
among multiple processors. A parallel processing system posse many numbers of processor with the objective of
running a program in less time by dividing them. This approach seems to be like divide and conquer. Examples are
NESL (one of the oldest one) and C/C++ also supports because of some library function.

2. DECLARATIVE PROGRAMMING PARADIGM


It is divided as Logic, Functional, Database. In computer science the declarative programming is a style of building
programs that expresses logic of computation without talking about its control flow. It often considers programs as
theories of some logic. It may simplify writing parallel programs. The focus is on what needs to be done rather how
it should be done basically emphasize on what code is actually doing. It just declares the result we want rather
how it has been produced. This is the only difference between imperative (how to do) and declarative (what to do)
programming paradigms.

Declarative programming is all about hiding away complexity and bringing programming languages closer to
human language and thinking. It's the direct opposite of imperative programming in the sense that the
programmer doesn't give instructions about how the computer should execute the task, but rather on what result
is needed.

This will be much clearer with an example. Following the same array filtering example in JavaScript, a declarative
approach might be:

const nums = [1,4,3,6,7,8,9,2]


console.log(nums.filter(num => num > 5))
// Output: [ 6, 7, 8, 9 ]

See that with the filter function, we are not explicitly telling the computer to iterate over the array or store the
values in a separate array. We just say what we want ("filter") and the condition to be met ("num > 5").

The nice thing about this is that it is easier to read and comprehend, and often shorter to write. JavaScript's
filter, map, reduce and sort functions are good examples of declarative code.

Another good example are modern JS frameworks/libraries like React. Take this code for example:

<button onClick={() => console.log('You clicked me!')}>Click me</button>


Here we have a button element, with an event listener that fires a console.log function when the button is clicked.

JSX syntax (what React uses) mixes HTML and JS in the same thing, which makes it easier and faster to write apps.
But that is not what browsers read and execute. React code is later on trans piled into regular HTML and JS, and
that is what browsers run in reality. JSX is declarative, in the sense that its purpose is to give developers a friendlier
and more efficient interface to work with.

An important thing to notice about declarative programming is that under the hood, the computer processes this
information as imperative code anyway.

Following the array example, the computer still iterates over the array like in a for loop, but as programmers we do
not need to code that directly. What declarative programming does is to hide away that complexity from the
direct view of the programmer.
a. Logic programming paradigms: It can be termed as abstract model of computation. It would solve logical
problems like puzzles, series etc. In logic programming we have a knowledge base which we know before and
along with the question and knowledge base which is given to machine, it produces result. In normal
programming languages, such concept of knowledge base is not available but while using the concept of
artificial intelligence, machine learning we have some models like Perception model which is using the same
mechanism. In logical programming the main emphasize is on knowledge base and the problem. The execution
of the program is very much like proof of mathematical statement, e.g., Prolog
predicates
sumoftwonumber(integer, integer).
clauses
sumoftwonumber(0, 0).
sumoftwonumber(N, R) :-
N > 0,
N1 is N - 1,
sumoftwonumber(N1, R1),
R is R1 + N.

b.Functional programming paradigms: The functional programming paradigms has its roots in mathematics and it
is language independent. The key principle of this paradigms is the execution of series of mathematical functions.
The central model for the abstraction is the function which are meant for some specific computation and not the
data structure. Data are loosely coupled to functions. The function hide their implementation. Function can be
replaced with their values without changing the meaning of the program. Some of the languages like Perl,
JavaScript mostly uses this paradigm.
Functional programming takes the concept of functions a little bit further. In functional programming, functions are
treated as first-class citizens, meaning that they can be assigned to variables, passed as arguments, and returned
from other functions. Another key concept is the idea of pure functions. A pure function is one that relies only on
its inputs to generate its result. And given the same input, it will always produce the same result. Besides, it
produces no side effects (any change outside the function's environment). With these concepts in mind, functional
programming encourages programs written mostly with functions it to defends the idea that code modularity and
the absence of side effects makes it easier to identify and separate responsibilities within the codebase. This
therefore improves the code maintainability.
Going back to the array filtering example, we can see that with the imperative paradigm we might use an external
variable to store the function's result, which can be considered a side effect.

const nums = [1,4,3,6,7,8,9,2]


const result = [] // External variable

for (let i = 0; i < nums.length; i++) {


if (nums[i] > 5) result.push(nums[i])
}

console.log(result) // Output: [ 6, 7, 8, 9 ]
To transform this into functional programming, we could do it like this:

const nums = [1,4,3,6,7,8,9,2]

function filterNums() {
const result = [] // Internal variable

for (let i = 0; i < nums.length; i++) {


if (nums[i] > 5) result.push(nums[i])
}

return result
}
console.log(filterNums()) // Output: [ 6, 7, 8, 9 ]

It is almost the same code, but we wrap our iteration within a function, in which we also store the result array. In
this way, we can ensure the function does not modify anything outside its scope. It only creates a variable to
process its own information, and once the execution is finished, the variable is gone too.

Examples of Programming Languages that suites the Functional programming paradigm


JavaScript: developed by Brendan Eich
Haskell: developed by Lennart Augustsson, Dave Barton
Scala: developed by Martin Odersky
Erlang: developed by Joe Armstrong, Robert Virding
Lisp: developed by John Mccarthy
ML: developed by Robin Milner
Clojure: developed by Rich Hickey

c. Database/Data driven programming approach: This programming methodology is based on data and its
movement. Program statements are defined by data rather than hard-coding a series of steps. A database program
is the heart of a business information system and provides file creation, data entry, update, query and reporting
functions. There are several programming languages that are developed mostly for database application. For
example, SQL. It is applied to streams of structured data, for filtering, transforming, aggregating (such as
computing statistics), or calling other programs. So it has its own wide application.
CREATE DATABASE databaseAddress;
CREATE TABLE Addr (
PersonID int,
LastName varchar(200),
FirstName varchar(200),
Address varchar(200),
City varchar(200),
State varchar(200)
);
LECTURE TWO
OBJECT ORIENTED PROGRAMMING
Object-oriented programming (OOP) is defined as a programming paradigm (and not a specific language) built
on the concept of objects, that is, a set of data contained in fields, and code, indicating procedures – instead of
the usual logic-based system.

Object Oriented means directed towards objects. In other words, it means functionally directed towards
modelling objects. This is one of the many techniques used for modelling complex systems by describing a
collection of interacting objects via their data and behavior.

It focuses on using objects and classes to design and build applications. Major pillars of Object-Oriented
Programming (OOP) are Inheritance, Polymorphism, Abstraction, and Encapsulation.

Object Oriented Analysis (OOA) is the process of examining a problem, system or task and identifying the objects
and interactions between them.

Object Oriented Programming (OOP) approach identifies classes of objects that are closely related to the methods
with which they are associated. It also covers the concepts of attribute and method inheritance. The
Massachusetts Institute of Technology was the first institution to utilize terminology referring to “objects” in the
sense that we use object-oriented programming today, in the late 1950s and early 1960s.

It is a method for storing data and the operations required to process that data based on the mathematical field
known as abstract data types. Programming could advance to a more abstract level thanks to OOP. Nearly all
developers employ the core programming paradigm known as object-oriented programming at some point in their
careers.

The well-known programming paradigm, OOP, is taught as the norm for most of a programmer’s educational
career. OOP is based on the idea of classes and objects. It organizes a computer program into basic, reusable
blueprints of code or “classes.” These classes are then used and reused to create new and unique objects with
similar functions. This paradigm represents a system that interacts with actual items in real life – such as the user.

Different parts of it perform actions on real-world items, creating actual interactions between people and
machines. The strategy is advantageous for collaborative development when projects are divided into groups due
to the organization of object-oriented software. Code reuse, scalability, and efficiency are other advantages of OOP.

The first stage in OOP is to gather all the objects that a programmer wishes to work with and determine their
relationships, a process known as data modeling. Data and functions are combined to create an object from the
data structure. Programmers can also establish connections between several objects. Objects can, for instance,
acquire traits from other objects.

A human is a straightforward illustration of an object. You would logically anticipate that a person would have a
name. This would be regarded as being in the person’s possession. Another thing you could expect from someone
is their ability to do, like walk or drive. One might view this as one of the person’s methods. Objects serve as the
framework for object-oriented programming code.
Once your objects are in place, you may use their interactions to achieve the desired outcome. Consider the
possibility of a show where someone gets in a car and drives it from point A to point B. Beginning with the objects
like a person or a vehicle is how you would describe them.

The use of ways is one example of this: a person can drive a car, and a car can be driven. For the individual to drive,
you must gather your items so that they are all in one place. When the object is identified, it is assigned a class of
objects that describes the type of data it contains and sequences logic that could modify the data in any way. A
method is any particular logic sequence. With clearly specified interfaces known as messages, objects may
communicate.

The Key Concepts/Pillars/ Features/ Characteristics of Object-Oriented Programming


Object Oriented Programming (OOP) is based on the concept of objects rather than actions, and data rather than
logic. In order for a programming language to be object-oriented, it should have a mechanism to enable working
with classes and objects as well as the implementation and usage of the fundamental object-oriented principles
and concepts namely inheritance, abstraction, encapsulation and polymorphism

1. Encapsulation: Encapsulation is the process of grouping functions and data into a single entity. This property
hides unnecessary details and makes it easier to manage the program structure. Each object’s implementation and
state are hidden behind well-defined boundaries and that provides a clean and simple interface for working with
them. One way to accomplish this is by making the data private. To access these data members, the member
function’s scope must be set to “public,” while the data members’ scope must be set to “private.” According to this
theory, an item contains all important information; only a small subset is made available to the outside world. Each
object has a private class that contains its implementation and state.

2. Inheritance: Inheritance, also called generalization, allows us to capture a hierarchal relationship between
classes and objects. For instance, a ‘fruit’ is a generalization of ‘orange’. Inheritance is very useful from a code
reuse perspective. Inheritance refers to the process of gaining properties. One object in OOP inherits the
properties of another. Developers can reuse common functionality while retaining a distinct hierarchy by assigning
relationships and subclasses between items. This characteristic of OOP speeds up development and provides more
accuracy by requiring a more in-depth investigation of the data. The parent-child relationship is symbolized via
inheritance.
3. Abstraction: This property allows us to hide the details and expose only the essential features of a concept or
object. This is the act of representing key features without including supporting information. It is a method for
developing a brand-new data type appropriate for a particular application. It avoids providing extraneous or
pointless facts and only displays the precise portion the user has requested. For example, a person driving a
scooter knows that on pressing a horn, sound is emitted, but he has no idea about how the sound is actually
generated on pressing the horn. It is crucial since it prevents you from performing the same task more than once.

4. Polymorphism: Poly-morphism means many forms. That is, a thing or action is present in different forms
or ways. One good example of polymorphism is constructor overloading in classes. Multiple classes can use the
same method name using polymorphism, which also involves redefining methods for derived classes. Compile-
time polymorphism and run-time polymorphism are the two different types of polymorphism. In addition to
having several forms, objects are made to have shared behaviors. To avoid writing duplicate code, the software will
determine which usage or meaning is required for each time an object from a parent class is used.

Other Key Concepts/Pillars/ Features/ Characteristics of Object-Oriented Programming include:


Class: A class is the fundamental unit of most programming language like C++, that paves the way for object-
oriented programming. It is a user-defined data type that can be accessed and used by creating an instance of that
class. It has its own data members and member functions. A class is comparable to an object’s blueprint. Both
member functions and data members are found in classes. The data members inside the class are manipulated
using these member functions.

5. Object: At the point of creation of a class, the description is the first object to be defined. An instance of a class
exists in an object. Notably, the system does not allocate any memory space when a class is specified, but it is
allocated when it is instantiated, that is, when an object is formed. Real-world things have state and behavior in
common, a pair of features. An object conceals its behavior through methods and keeps its information in
attributes.

6. Syntax: The principles that specify how a language is structured are known as syntax. In programming languages
(rather than natural languages like English), syntax is the set of rules that define and guide how words,
punctuation, and symbols are organized in a programming language. Without syntax, it is almost difficult to
comprehend the semantics or meaning of a language. A compiler or interpreter woold not be able to understand
the code if the syntax of a language is not adhered to.

6. Coupling: Coupling describes the degree to which one software element is connected to another. Software
elements can be a class, package, component, subsystem, or system. It denotes the level of familiarity one object
or class has with another. This means that if one class changes its attributes, the dependent changes in the other
will also change. The magnitude of interdependence between the two classes will determine how these changes
occur.

7. Cohesion: A class’s cohesion is determined by how closely and meaningfully coupled to one another its methods
and properties are, as well as by how intently they are focused on carrying out a single, clearly defined goal for the
system. This is a measure of how narrowly focused a class’s responsibilities are. Because their methods and
properties do not relate to one another logically, low cohesive classes are challenging to maintain.

8. Association: An association is a relationship between two distinct classes that are established with the aid of
their objects. One-to-one, one-to-many, many-to-one, and many-to-many associations are all possible. An
association is a connection between two things. The diversity between objects is defined by one of Java’s OOP
concepts. There is no owner in this OOP concept, and each object has a distinct lifecycle.
9. Aggregation: In this method, each object has a distinct lifecycle. Ownership, however, prevents the child object
from being a part of another parent object. Java aggregation depicts the link between an object that contains
other objects and is a weak association. This illustrates the connection between a component and a whole, where
a part can exist without a whole. A unique type of semantically weak link called an aggregation occurs when
unrelated things are combined.

10. Composition: Composition is an association that depicts a relationship between a part and a whole in which a
part cannot exist without a whole. Aggregation can take a variety of forms, including composition. Since child
objects lack a lifecycle, they all automatically disappear when the parent object does. One object cannot exist
without the other in any composition between two entities. As a result, both entities depend on one another in
their composition.

11. Modularity: Modular design refers to the division of a system into many functional pieces (referred to as
modules) that can be combined to create a more extensive application. Modularity and encapsulation are
inextricably related. When mapping encapsulated abstractions into actual, physical modules, high cohesion within
the modules and limited inter-module interaction or coupling can be seen as the definition of modularity.

12. Constructors and methods: A constructor is a specific kind of subroutine called to create an object. It sets up
the new object for use and frequently accepts arguments from the constructor to set up necessary member
variables. In OOP, a method is a procedure connected to a message and an object. An object’s state data and
behavior make up its interface, which describes how any of its numerous consumers may use it. A method is a
consumer-parameterized object activity.

Advantages of Object-Oriented Programming


1. Enables code reusability: The idea of inheritance is one of the critical concepts offered by object-oriented
programming. A class’s attributes can be passed down through inheritance, eliminating the need for duplication of
effort. Doing this prevents the problems associated with repeatedly writing the same code.Due to the introduction
of the idea of classes, the code section can be used as many times as necessary in the program. A child class that
uses the inheritance method inherits the parent class’s fields and methods. One can readily alter the parent class’s
available methods and values.

2. Increases productivity in software development: We can create programs from pre-written, interconnected
modules rather than having to start from scratch, which would save time and increase productivity. Thanks to the
OOP language, we can break the software into manageable, discrete problems. Because it allows for the division of
labor in the creation of object-based programs, object-oriented programming is modular.It is also extendable, as
you may add new characteristics and actions to objects. One can utilize objects in several applications. Object-
oriented programming increases software development productivity, compared to conventional procedure-based
programming techniques, due to modularity, extensibility, and reusability.

3. Makes troubleshooting simpler: When object-oriented programming is used, troubleshooting is made simpler
since the user knows where to look in the code to find the source of the problem. Since the error will indicate
where the issue is, there is no need to inspect additional code areas. All objects in object-oriented programming
(OOP) are self-constrained, which is one benefit of employing encapsulation. DevOps engineers and developers
gain a lot of advantages from this multimodal behavior because they may now work on several projects at once
with the benefit of avoiding code duplication.

4. Reinforces security: To maintain application security and provide vital data for viewing, we are filtering out
limited data through data hiding and abstraction mechanisms. The concept of data abstraction in OOPS allows only
a small amount of data to be displayed to the user, which is one of OOP’s strong points.When only the necessary
info is accessible, the rest is not. As a result, it makes security maintenance possible.
5. Simplifies code maintenance: Object-oriented software is simpler to maintain in terms of code. Because of the
design’s modularity, one can upgrade a portion of the system in the event of problems without calling for
significant adjustments. Additionally, you can modify already-existing objects to create new ones. Any
programming language would benefit from having this capability; it prevents users from having to redo work in a
variety of ways. Maintaining and updating the current codes by adding new changes is always simple and time-
saving. Since one can produce new objects with just minor variations from old ones, it is simple to maintain and
modify current code.

6. Prevents the repetition of data: Redundant data refers to data that has been duplicated. As a result, the same
information is repeated. The redundancy of the data is seen as a benefit in object-oriented programming. For
instance, the user would like the capability comparable to that of practically all classes.
In such circumstances, the user can construct classes with comparable functionality and inherit them when
necessary. A significant benefit of OOP is the redundancy of data. Users who want a comparable feature in
numerous classes can write standard class definitions for those features and inherit them.

7. Results in flexible code: Polymorphism is the idea that allows for flexibility. The following advantages of
polymorphism for developers are extensibility and simplicity. One advantage of OOP is polymorphism, which
allows a piece of code to exist in more than one version. For instance, you might act differently if the setting or
environment changes.Let us look at a simple example. In a market, a person will act like a customer; in a school, a
person will act like a student; and in a home, a person will act like a son or daughter. Here, the same person
exhibits various behaviors depending on the environment.

8. Addresses issues early on: Another benefit of object-oriented programming is that it may effectively solve
problems by being divided into smaller components. It becomes good programming practice to deconstruct a
complex issue into simpler parts or components. Given this information, OOPS uses a feature that divides the
program code into smaller, more manageable chunks developed one at a time.Once the issue has been
disassembled, you can put the individual pieces to use again to address additional problems. Additionally, one
might use the modules with the same interface and implementation details to replace the more minor codes.

9. Provides design advantages: A significant development in software engineering has been object-oriented
development. Among other things, it promises to shorten development duration and give firms a competitive
advantage. The design benefit that users will experience from OOPs is the ease with which they can design and fix
things and the reduction of hazards, if any. Here, object-oriented programs require a lengthy and thorough design
phase from the designers, which produces better designs with fewer faults. It is simpler to program all the non-
OOPs independently after a certain point when the program has hit some fundamental constraints.

10. Lowers development costs: Using an object-oriented approach does make it possible to cut back on some of
the direct costs involved with systems, including maintenance and development. Reusing software also reduces the
price of development. In most cases, more time and effort are spent on object-oriented analysis and design,
reducing the overall development cost. The general cost of the improvement is reduced since more effort is
typically put into the article-specific assessment and plan. The development cost is generally reduced since more
time and effort are usually spent on object-oriented analysis and design.

You might also like