Object Oriented Programming (OOP): Encapsulation, Polymorphism, and Inheritance

Initially all programming was done by structured programming as in C language. In C language, programs are organized around the code. C had a great potential to become one of the best languages, but it lacked one thing, to handle complex programs. When the programs were scaled structured programming used in C was a bit difficult for the programmers and the compilers. Hence the inception of Object oriented programming where the program is organized around the data. In OOP (C++) data and routines are defined which acts on the data having properties such as encapsulation, polymorphism, and inheritance.

Encapsulation: It is a process of binding code and data together called black box and keeping it safe from outside. This code and data binding is called as an object where code and data can be private or public to the object. This object acts as a variable to the user defined type. That means each object created is a new data type and each specific instance of this new data type is a compound variable. If a code and data is private then it is not accessed by codes outside the object. If a code and data is public then it can be accessed by codes outside the object.

Polymorphism: It is an attribute that allows one interface to control many methods. Here the word polymorphism is derived from poly meaning “many” and morphism meaning “forms”. Polymorphism uses the concept of having one interface and multiple processes. It is used for avoiding complexities while programming. Here the compiler has to pick a suitable method for a particular program and not the programmer. A programmer doesn’t have to write routines on how the processes will be executed  It is the task of the compiler to decide the best possible process. C++ supports run time as well as compile time polymorphism. By Polymorphism the developed code is readable, clean, sensible, and resilient.

Inheritance: It is a process by which one object can attain the properties of another object. It works on the principle of hierarchical classification (top down approach). By this an object has to define only the specific characteristics that make it unique. Thus, making the code simpler. By inheritance, you can reuse the code over and over again without starting from the scratch. Inheritance works on the principle of parent and child. Each child inherits general attributes of the parent. For Example: Electronic System can be considered as a class for electronic gadgets. Now, a computer is a child of this particular class. So, basically a computer inherits all the general characteristics of the parent class Electronic gadgets. Again if we classify further, a laptop is a child of the parent class computer.

In Object Oriented programming, all three concepts, encapsulation, inheritance and polymorphism are applied together. Languages which use the process of Object Oriented programming are: C++, Java, C#, Python, etc.

Leave a Reply