What Is Object-Oriented Programming?

What Is Object-Oriented Programming?



Basically, "Object-Oriented Programming" is a programming paradigm that relies on data, classes, and objects rather than functions and logic. We're using objects in programming, just as their name might suggest. By using object-oriented programming, a software program can be organized into simple, reusable pieces of code blueprints (usually called classes), which can be used to create individual instances of objects. JavaScript, c++, Java, and Python are among the many object-oriented programming languages.

Object-Oriented Programming allows us to wrap everything up into different classes. And to access the methods, we need to create an instance/object of the class and use the variable associated with that instance/object. The process of writing object-oriented programs involve creating classes that can be reused repeatedly to write new programs, objects are created from those classes, and applications, which are standalone executable programs that utilize those objects. Now, thinking in object-oriented programming involves program components being conceptualized as objects that belong to classes and are closely related to concrete objects in the real world; you can then manipulate these objects and interrelate them to achieve the desired result.


Basic Concepts of Object-Oriented Programming

            Object-Oriented Programming

1.  Class: A class is a user-defined Data Type. Classes have Data Members and Member Functions (also called Methods) (and both are known as the class members), and these are accessible only by creating an instance/object of that class. Classes are essentially templates that define the type and form of an object. The physical representation of a class does not exist in memory until an object of that class is created. If you declare a class, you also declare what data it contains and what code operates on that data. Data is contained in instance variables considered to be data members of the class, while code resides in the functions defined by the class known as member functions. For Example: Consider the Class of Scooter. Scooters may come in different names and brands, but they are similar in many aspects, such as having two wheels, speed limit, mileage range, etc. So here, Scooter is the class, and wheels, speed limits, and mileage are their properties.

2.  Object: An object is an instance of a class representing real-life entities in object-oriented programming. An object is a set of data fields with unique attributes (characteristics), states, and behaviors. An object contains data as well as code to manipulate the data. There is no need to know the data or code of others to interact freely for objects, and it is enough to know the message accepted and the response returned by each object. For Example- pen, chair, mobile, laptop, car, Scooter, tablet, etc.

3.  Data Abstraction: Abstraction is a process to remove unwanted materials and abstract only the helpful and important stuff. Or we can say that exposing high-level details and hiding low-level details of an object from the outside world is known as Abstraction. In object-oriented programming, external interfaces are supported, so there is no need to look into the inner details. The object may be composed of many smaller ones, each with an appropriate interface. Data abstraction is the practice of hiding internal details from the user not to have to know about them. The user only has to understand or know the external interface of an object to use it. By Abstraction, the object can maintain its security.

4.  Encapsulation: Encapsulation is a programming technique that binds together features and behavior within a single unit, ensuring that both are protected from outside interference and misuse. In a class, the code or data may be private to that object or public. Private code or data is known to and accessible by only another part of the object. That is, the private parts of your program cannot access the object's data or code that exists outside the objects, but the public parts can even though it is defined within an object. The public parts of an object serve as a controlled interface to the private parts of the object. As we can see in Encapsulation, the variables and data of a class are hidden from other classes and can only be accessed through the member function of the class in which they are declared. In the same way, the data of a class is hidden from other classes, so it is also known as data-hiding. Good Encapsulation always results in better Encapsulation & vice-versa. Encapsulation and Abstraction are mutual with each other. As the level of Encapsulation degrades, Abstraction also degrades.


Encapsulation

5.    Inheritance: Inheritance is the crucial technique of object-oriented programming (OOP) by which one class (derived class) can inherit the properties and characteristics of another class(base class). It allows one to create classes in a hierarchy, from the most general to the most specific. When one class inherits another, the inherited class is called the base class, and the inheriting class is called the derived class. In Object-Oriented Programming, the concept of inheritance provides the idea of reusability. The purpose of inheritance is to make it possible to reuse code whenever it's possible, thereby reducing its redundancy. So when creating a new class, we no longer need to write all its properties and functions again and again as they can be inherited from another class(base class).

                                         

      Simple Inheritance                 

6.  Polymorphism: The word Polymorphism comprises two words poly and morphism. Here, poly means many, and morphism derives from the word morph meaning "transforming of an object". Well, it is a Greek word that means many forms. We can define Polymorphism as a feature that permits one interface to be used for a general class of actions while the specific situation determines the exact nature of each action. All real-life objects are polymorphic in nature i.e.; they are used to change their form—these form changes in their behavior. We named things according to their utilization and to similar kinds of things; we try to assign common names. Polymorphism in object-oriented programming is basically of two types: 1. Compile Time Polymorphism and 2. Runtime Polymorphism.

         Polymorphism

7.    Dynamic Binding: Dynamic binding has been used in object-oriented programming in conjunction with Polymorphism and inheritance. It's also called dynamic dispatch, runtime binding, or late binding. This is the process of linking a procedure call to a specific code sequence at runtime to resolve calls to methods overridden by a procedure. Let's say we have a superclass vehicle with a speed method and subclasses of Two-Wheeler and four Wheeler (with the implementation of speed methods in each class). As a result of this, method overriding is an example of dynamic binding since both the base class and derived class has the same method name, and it is the type of object that determines the method to be executed.

 

 

8.   Message Passing: This is an object-oriented technique used in parallel programming, where objects communicate with each other by sending and receiving information. Message passing involves specifying an object, a function, and the information that will be sent via the message. When sending a message to an object, it will call the appropriate procedure in the receiving object.


Message Passing


Comments