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

OOP paradigm with examples

Object-Oriented Programming (OOP) is a programming paradigm that utilizes classes and objects to enhance software development and maintenance. Key concepts include classes, objects, attributes, methods, encapsulation, inheritance, abstraction, and polymorphism, each contributing to code reusability, modularity, and extensibility. However, OOP also presents challenges such as increased complexity, potential performance issues, and not being suitable for all programming tasks.

Uploaded by

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

OOP paradigm with examples

Object-Oriented Programming (OOP) is a programming paradigm that utilizes classes and objects to enhance software development and maintenance. Key concepts include classes, objects, attributes, methods, encapsulation, inheritance, abstraction, and polymorphism, each contributing to code reusability, modularity, and extensibility. However, OOP also presents challenges such as increased complexity, potential performance issues, and not being suitable for all programming tasks.

Uploaded by

anee.cse8.bu
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

OOP paradigm with examples

Object-Oriented Programming
Object oriented programming is a methodology or paradigm to design a program
using classes and objects. It simplifies the software development and
maintenance by providing some concepts defined below:

1. Class: Class is a user-defined data type which defines its properties and its
functions. Class is the only logical representation of the data. For example,
Human being is a class. The body parts of a human being are its properties,
and the class actions performed by the body parts are known as functions.
The class does not occupy any memory space till the time an object is
instantiated.

2. Object: Object is a run-time entity. It is an instance of the class. An object


can represent a person, place or any other item. An object can operate both
data members and member functions.
public static void main(String[] args) {
Student objOne = new Student();
objOne.name = “Tahira”;
}

3. Attribute: An attribute is a specification that defines the property of an


object. It may also refer to set the specific value for a given instance of such.
These are typically represented as variables within a class and can represent
properties of the objects that will be created from the class.
4. Method: In Object-oriented Programming (OOP), a method is a block of
code or function that is associated with an object and is allowed to access
and modify the data inside tat object. Methods define the behavior of an
object. They are declared inside a class and are used to perform specific
tasks.

5. Encapsulation: Encapsulation is the process of combining data and


functions into a single unit called class. In Encapsulation, the data is not
accessed directly; it is accessed through the functions present inside the
class. In simpler words, attributes of the class are kept private and public
getter and setter methods are provided to manipulate these attributes.
Thus, encapsulation makes the concept of data hiding possible.

6. Inheritance: Inheritance is a process in which one object acquires all the


properties and behaviors of its parent object automatically. In such a way,
you can reuse, extend or modify the attributes and behaviors which are
defined in other classes.
In java, the class which inherits the members of another class is called
derived class and the class whose members are inherited is called base
class. The derived class is the specialized class for the base class.

7. Abstraction: Abstraction is mainly used to hide the complexity of large


systems by splitting them into smaller, more manageable modules or
classes. Each module has a specific task. Each module is built separately and
then they are combined to form a large system.
In simple terms, it is hiding the unnecessary details & showing only the
essential parts/functionalities to the user.
8. Polymorphism: Polymorphism is the ability to present the same interface
for differing underlying forms (data types). With polymorphism, each of
these classed wills have different underlying data. Precisely, Poly means
“many” and morphism means “forms”.

Object-Oriented Programming (OOP) has been a popular paradigm for software


development for many years. It has both advantages and disadvantages, which
I’ll outline below:

Pros of Object-Oriented Programming:


• Reusability: OOP makes it easy to reuse code by creating classes that
can be used in multiple programs. This can save time and effort, and it can
also help to ensure that code is consistent across different programs.
• Modularity: OOP helps to break down programs into smaller, more
manageable modules. This makes programs easier to understand,
maintain, and test.
• Abstraction: OOP allows programmers to abstract away the details of
how objects work, so that users can focus on what the objects do, rather
than how they do it. This can make programs easier to use and
understand.
• Extensibility: OOP makes it easy to add new features to programs
without having to change existing code. This is because new features can
be added by creating new classes that are inherited from existing classes.

Cons of Object-Oriented Programming:


• Complexity: OOP can be more complex than other programming
paradigms, such as procedural programming. This is because OOP
requires programmers to think about data and behavior as separate
entities.
• Performance: OOP can sometimes lead to slower program execution,
especially if objects are heavily interconnected.
• Memory usage: OOP can sometimes lead to increased memory usage,
especially if objects are large or if they are created and destroyed
frequently.
• Overuse of inheritance: Improper use of inheritance can lead to rigid and
inflexible codebase, making it difficult to modify and extend the system
without causing unexpected side effects.
• Not suitable for all problems: While OOP is beneficial for certain types of
applications, it may not be the best choice for all programming problems.
Some tasks may be better suited to other paradigms like functional
programming or procedural programming .

You might also like