Object-oriented programming (OOP) is a programming paradigm based on the concept of “objects”, which can contain data and code. It is used by nearly every developer at some point in their career. OOP is the most popular programming paradigm in the field of computer science. It relies on the concept of classes and objects. It is used to structure a software program into simple, reusable pieces of code blueprints. There are many object-oriented programming languages including JavaScript, C++, Java, and Python.
Objects:
This is the basic unit of object-oriented programming. Object can be a combination of variables, functions, and data structures, in particular in class-based variations of the paradigm it refers to a particular instance of a class. Objects can be declared several times depending on the requirements.
Classes:
Classes are a blueprint or a set of instructions to build a specific type of object. It is also a basic concept of Object-Oriented Programming which revolves around real-life entities. Class in Java determines how an object will behave and what the object will contain. A class is used to bind data as well as methods together in a single unit.
Principles of OOP:
There are four principles of object oriented programming(OOP).
- Inheritance
- Encapsulation
- Abstraction
- Polymorphism
Inheritance:
Inheritance is a mechanism of acquiring the features and behaviors of a class by another class. Using inheritance, we can create a derived class from a base class such that it inherits the properties and methods of the parent class(base class) and can have its own additional properties and methods. The derived class is also known as the child class.
There are 6 different types of inheritance in OOP.
- Single inheritance
- Multi-level inheritance
- Multiple inheritance
- Multipath inheritance
- Hierarchical Inheritance
- Hybrid Inheritance
Encapsulation:
Encapsulation means carrying all the important information inside an object. encapsulation is also often used to hide the internal state of an object from the outside. This process is called information hiding. The general idea of this mechanism is that If you have an attribute that is not visible from the outside of an object, and bundle it with methods that provide read or write access to it, then you can hide specific information and control access to the internal state of the object.
In Encapsulation, Only public methods and attributes are accessible from the outside. Code is hidden in a class, only public methods are accessible by the outside developers.
Abstraction:
In Object Oriented Programming, abstraction means implementation is hidden from the user and only required functionality will be accessible or available to the user. Abstraction uses simplified high level tools to access a complex object. Abstraction is an extension of encapsulation.
Abstraction also plays an important security role by only displaying specific or selected data to users.
Polymorphism:
The word polymorphism means having many forms. Using inheritance, objects can override shared parent behaviors, with specific child behaviors. Polymorphism allows the same method to execute different behaviors in two ways: method overriding and method overloading.
What is Object Oriented Programming? OOP Explained in Depth (educative.io)
What is object-oriented programming (OOP)? (tutorialspoint.com)
Object-oriented programming – Wikipedia
From the blog CS@Worcester blog – Syed Raza by syedraza089 and used with permission of the author. All other rights reserved by the author.