Object Oriented Programming (OOP)
Characteristics of OOP
- Emphasis is on data rather than procedure.
- Programs are divided into objects.
- Data structures are designed such that they characterize the objects.
- Functions that operate on the data of an object are tied together in the data structure.
- Data is hidden and cannot be accessed by external functions.
- Objects may communicate with each other through functions.
- New data and functions can be easily added whenever necessary.
- Bottom-up approach is followed in program design.
Advantages of OOP:
- We can eliminate redundant codes by using inheritance feature of OOP.
- It is very easy for managing complex and large size problems.
- The most important is the reusability of codes by using the features inheritance.
- It takes very less time for the development and maintaining the software.
- It is efficient for testing and implementation of the system.
- It follows a bottom-up approach.
- It can be implemented in the field of OODBMS, OOAD, and different fields of engineering.
Disadvantage of OOP:
- Size: Object-oriented programs are much larger than other programs.
- Effort: Object-oriented programs require a lot of work to create.
- Speed: Object-oriented programs are slower than other programs.
Features of OOP:
Object
Class
Data Abstraction
Encapsulation
Inheritance
Polymorphism
Message Passing
Modularity
Reusability
Flexibility and Scalability
In OOP, everything revolves around objects. An object is a self-contained unit that represents a real-world entity or concept. It combines data (attributes) and behaviors (methods or functions) related to that entity.
A class is a blueprint or template for creating objects. It defines the common structure and behavior that its objects will possess. Think of it as a set of instructions for building objects.
Data abstraction is the process of simplifying complex reality by modeling classes based on their essential attributes and behaviors while hiding unnecessary details. It allows you to focus on what an object does rather than how it does it.
Encapsulation is the concept of bundling an object's data (attributes) and methods (functions) into a single unit, called a class. It also involves restricting access to certain parts of an object, ensuring that data can only be accessed and modified through well-defined methods.
Inheritance is a mechanism that allows you to create a new class (derived or child class) based on an existing class (base or parent class). The derived class inherits the attributes and behaviors of the base class and can extend or override them.
Polymorphism means "many shapes" and refers to the ability of objects of different classes to respond to the same method or function call in a way that is appropriate for their specific class.
In OOP, objects communicate by sending messages to each other. This is often accomplished through method calls. When an object needs to perform a specific action or request information from another object, it sends a message, and the recipient object responds accordingly.
OOP promotes modularity by breaking down a large system into smaller, manageable pieces (objects or classes). Each module (object) focuses on a specific aspect of the system's functionality.
OOP emphasizes code reusability through the use of classes and inheritance. Once you've created a well-designed class, you can create multiple instances of it (objects) and reuse that class in different parts of your program or even in different projects.
OOP provides a flexible framework for building software. As the requirements of a system evolve, you can extend existing classes or create new ones without affecting the rest of the codebase.
Difference Between OOP and POP
OOP | POP |
---|---|
It stands for Object Oriented Programming. | It stands for Structure Oriented Programming. |
Program is divided into objects. | Program is divided into functions. |
Bottom-up approach. | Top-down approach. |
Inheritance property is used. | Inheritance is not allowed. |
It uses access specifier. | It doesn't use access specifier. |
Encapsulation is used to hide the data. | No data hiding. |
Concept of virtual function. | No virtual function. |
EXAMPLE: C++, Java. | EXAMPLE: C, Pascal. |