Procedural programming focuses on function and procedure whereas object-oriented programming focuses on class and objects. OOP binds the data and the functions that operate on them so that data can be abstracted, which is one of the important features of object-oriented programming. These objects are organized into classes, which allow individual objects to be grouped together.
OOP focuses on collecting all of the objects a programmer wants to manipulate and identify how they relate to each other. We will study about Class and Objects in our next chapter. The important features of Object-Oriented programming are:
- Class & Object
Encapsulation is defined as the hiding of sensitive data from the user by wrapping data under a single unit. Data of a class are encapsulated so that other classes and objects can’t access those data without special access permission. Encapsulation provides greater data security.
To achieve encapsulation, we must declare class variables/attributes as private. Private is an access specifier that defines how the members (attributes and methods) of a class can be accessed. Other access specifiers are public, protected.
Abstraction refers to the process of hiding the internal behavior of the program and showing only user understandable code. It hides the internal structures, data types, objects, and functions which helps developers make changes and additions over time more easily.
By virtue of data abstraction only the essential details are displayed to the user hiding any unnecessary implementation code. Let’s take a famous real-world example of a man calling his friend. The man needs to know to dial numbers or needs to know to pick up the phone. But he doesn’t know how his phone gets connected to his remote friend. This is what abstraction is.
Inheritance refers to the concept of inheriting behaviors of the existing class to the new classes or objects. It means many child classes can be derived from the child class with some or behaviors inherited. Child classes are also known as derived classes.
We will study about inheritance in our next chapter in detail.
- Improve maintainability.
- Reduce Cost.
- Avoid re-code and supports re-usability.
Polymorphism refers to certain items appearing in different forms or ways. It provides the ability for classes to provide different implementations of methods that are called through the same name. We will study about polymorphism in our next chapter in detail.
- 1. OOP provides importance on data rather than procedures or functions.
- 2. Data and associated processes are unified, grouping objects with common attributes, operations, and semantics.
- 3. OOP supports data hiding by making it accessible only to the class in which it is defined.
- 4. OOP approach helps in reducing the code size since classes can be just derived from the existing one and one needs to add only the new features and it helps users to save their time.
- 5. OOP extends the handling of data types and operations.
- 6. OOP hides unnecessary details in classes and delivers a simple and clear interface for working.
This page is contributed by Diwas. If you like AIHUB and would like to contribute, you can also write an article & mail your article to firstname.lastname@example.org . See your articles appearing on AI HUB platform and help other AI Enthusiast.