OBJECT ORIENTED PROGRAMMING

In this blog we study the basic concepts of object oriented programming, how it differs from Procedural oriented programming, advantages and it's features with examples.

Definition

Object Oriented Programming(OOP) is an approach that provides a way of modularizing programs which is using "objects" to represent data(variables) and methods(functions).

A single module can be used as a template so that we can create as many copies of each module on demand.

Procedural vs Object Oriented Programming

Procedural vs Object Oriented Programming
Procedural Oriented Object Oriented
Major focus is on functions. Major focus is on data and how to access them.
Programs are divided into functions. Programs are divided into objects that contains data and functions.
Data is usually global and focus on how to access data is not taken into account. Data is hidden and mainly focuses on how to access data.
Not suitable for real world scenarios. Higly suitable and also resembles the real world scenarios.
Data is publicly available. Data is hidden and cannot be accessed directly.
Ex languages: Fortran, COBOL, Pascal, C etc. Ex languages: C++, Java, Python, Swift, C#, Ruby, Dart, R etc.

Advangates of OOPs

  • OOPs makes development and maintenance easier where as in Procedure-oriented programming language it is not easy to manage if code grows as project size grows.
  • OOPs provides data hiding whereas in Procedure-oriented programming language a global data can be accessed from anywhere.
  • OOPs provides ability to simulate real-world event much more effectively. We can provide the solution of real word problem if we are using the Object-Oriented Programming language.

Features of OOPs

Features of OOPs
Features Meaning
Classes A class is a template that is a collection of data members(variables) & methods(member functions). It is a bluprint that defines the data & behavior of a given type. Classes are usually user defined data type.
Ex: A class named Book can be created with data(book id, name, author, cost) and methods(to add new book, to get details of specific book).
Objects An object is a real world entity and is an instance of a class. Once a class is created then we can create any number of copies of that class using objects. Objects are an abstract data type and it can include multiple properties.
Ex: Any no. of objects can be created of class Book like a book for author ABC; a book for author XYZ etc.
Data Encapsulation Data encapsulation provides a way for binding data and methoids into single entity called class. In encapsulation, data is not accessed directly instead it is accessed using through the methods present inside that class.
Ex: Consider our phone contacts as a class; the contact no. and contact name are the data, the edit, call, message options are the methods that provides us to interact/access the contact.
Data Abstraction Data abstraction provides a way of hiding the internal details and shows only the functionality. Through this process, a programmer needs to hide the background features and relevant data about an object that reduces the complexity and increases the efficiency.
Ex: In mobile phones, we don't know how bluetooth works but we clearly know how to use it. Or, a user need not worry about working of a linked list, he just need to know how to add/delete/update/search data.
Polymorphism Polymorphism means many(poly) forms(morphism). It provides a way of perfoming similar tasks in different ways. It refers to programming language's ability to process objects differently depending on thier data type or class.
Ex: A + operator can be used to add two numbers or strings. A function can be overloaded and accessed depending on it's parameters type and return type.
Inheritance Inheritance is way of inheriting the properties of one class to another. It allows users to create derived class(subclass) from an existing class(superclass). Now this derived class inherits all the proerties from the superclass/baseclass and can also have it's own features. It is used to achive runtime polymorphism.
Ex: A new derived class named Cart can he inherted from class Book that inherits Book's properties and can also have it's own properties like quantity, total cost, shipment address etc.
Message Passing Message passing provides a way for objects to interact with each other.
Ex: In case we need a new object that has same properties of an existing one then we can clone this existing object.

That's it from this blog post. If you liked it then do share this blog with your friends or people who wanna get into programming world. Thank You!

Copyright © NStF Blogs 2021