About Me

Hello there! Before talking about qualifications and professional abilities, I would like to introduce myself. I am a Yuvraj Basnet and professional software developer and have been working in this field for 3 long years. I have finished my graduation from The University of Delhi on Computer Science Engineering I considered myself a reasonably experienced programmer with a particular interest in the human side of software development, computers are fascinating machine, but they're mostly reflection of the people using them. In the art of software development, studying code isn't enough; you have to study the people behind the software, too.

Object Oriented Programming in C++


Object Oriented Programming in C++

Object-oriented programming – OOP uses objects in programming. Object-oriented programming purpose to implement real-world entities like polymorphism, inheritance, hiding, etc in programming. The main purpose of OOP is to bind together the data and the functions that operate on them so that no other part of the code can access this data except that function.


Characteristics of an Object Oriented Programming language:


1. Class: The building block of C++ that leads to Object-Oriented programming is a Class. It is a user-defined data type, which holds its own data members and member functions, which may be accessed and employed by creating an instance of that class. A class is alike of a blueprint for an object. 

For Example: Consider the Class of Cars. There could also be many cars with different names and brand but all of them will share some common properties like all of them will have 4 wheels, regulation , Mileage range etc. So here, Car is that the class and wheels, speed limits, mileage are their properties. 

A Class may be a user-defined data-type which has data members and member functions. 
Data members are the info variables and member functions are the functions used to manipulate these variables and together these data members and member functions define the properties and behavior of the objects in a Class. 

In the above illustration of class Car, the member functions can apply brakes, increase speed etc. The data member are going to be regulation , mileage etc 

We can say that a Class in C++ is a blue-print representing a group of objects which shares some common properties and behaviors.

2. Object: An Object is an perceptible entity with some behavior and characteristics . An Object is an instance of a Class. Generally when a class is defined at this time no memory is allocated but when it is instantiated (i.e. an object is created) memory is allocated.


Object take up space in memory and have an associated address like a record in structure or union in C.

When a program is executed the objects communicate by sending messages to one another.

Every object contains code and data to manipulate the data. Objects can communicate without having to know details of each other’s code or data, it is sufficient to know the type of message accepted and type of response returned by the objects.

3. Encapsulation: Encapsulation is defined as wrapping up of data and information under a one unit. In Object-Oriented Programming, Encapsulation is defined as the data and the functions together that manipulate them.


let us take a real-life illustration of encapsulation, in a car company, there are different sections like the accounts section, sales section, finance section etc. The finance section handles all the financial transactions and accounts keep records of all the data related to money. Similarly, the sales section handles all the sales-related activities and keeps records of all the car sales. Now there may be arise a condition when some reason an official from the finance section needs all the data about car sales in a particular week. In this case, he is not allowed or enabled to directly access the data of the sales section. Manager will first have to contact some other senior officers in the sales section and then request him to give the particular data. This is what encapsulation is. Here the data of the sales section and the employees that can manipulate them are wrapped under a single name or unit i.e, “sales section”.

Encapsulation also leads to abstraction or data hiding. As using encapsulation also hides the data. In the above illustration, the data of any of the section like finance, sales, or accounts are hidden from any other section.

4. Data Abstraction: Data abstraction is most essential and important features of object-oriented programming in C++. Abstraction means displaying only important information and hiding the background details. Data abstraction may be defined as providing only important information about the data to the outside world, hiding the implementation or background details.

Let us take  a real-life illustration Suppose you are operating a Laptop. You know that the important feature of a laptop is the RAM, processor, battery life, design and build. But, while operating the laptop you do not get into the operational details of the laptop such as how the CPU of the laptop allocates memory for the various media on your laptop or other intricate architectural details of the laptop. All these details aren’t visible to laptop users from a non-technical background.

Abstraction using Classes: We all know that using classes we can implement data abstraction. The class helps us to group data members and member functions by using available access specifiers in C++. A Class can take decision which data member will be visible to the outside world and which is not.

Abstraction in Header files: We have one more type of data abstraction in C++ i.e,  header files. For example,  the sqrt() method present in math.h header file. Whenever we need to calculate the square root of a integers, we can simply call the function sqrt() present in the math.h header file and pass the numbers as parameters without knowing the algorithm according to which the function is actually calculating the square root of numbers.

5. Polymorphism: The meaning of word polymorphism is having many forms. In simple words, polymorphism may be defined as the ability of a message to be displayed in more than one form.

let us take a real life example of polymorphism, A man at the same time can have different characteristic. Like a man at the same time is a husband, a father, an worker. So the same man have different behavior or characteristic in different situations. 

let us take second real life example of polymorphism, Suppose if you are in market at that time you behave like a buyer, you are in class room that time you behave like a student, when you at your home at that time you behave like a daughter or son, Here one person have different-different behaviors. This is called polymorphism.

An operation may display different characteristics in different instances. The characteristics or behavior depends upon the types of data used in the operation.

C++ supports operator overloading and function overloading.

Operator Overloading: The process of making an operator to display different characteristics in different instances is known as operator overloading.

Function Overloading: Function overloading refers to using a single function name to perform different types of tasks.

At the time of inheritance programmers used concept of polymorphism.

6. Inheritance: Inheritance may be defined as the capability of a class to derive properties and characteristics from other class is called Inheritance. Inheritance is one of the most essential features of Object-Oriented Programming in C++.

Sub Class: Class that inherits properties from another class is known as Sub class or Derived Class.

Super Class: Class whose properties are inherited by sub class is known as Super class or Base Class

Reusability: Inheritance supports “reusability” means when programmer wants to create a new class and there is already a class that includes some of the code or statements that programmers want, programmer can derive our new class from the old one. By doing this, programmer are reusing the fields and methods of the existing class.


7. Dynamic Binding: It is the feature of OOP. Here in dynamic binding the compiler, doesn't knows in advance that which of the function (with same name and arguments in parent and child class) is to call when an object of the classes (parent or child) are call the function here the compiler will decide at the run time. That is why it is also called Late Binding. 

8. Message Passing: Message Passing refers to means of communication between different threads within a process, different process running on same Node and different process running on different Node. 
In this a sender or a source process sends a message to a known receivers or destination process.
Message has a predefined structure and message passing uses two System call: Send and Receive

send (name of destination process, message);
receive (name of source process, message); 











Post a Comment

2 Comments

  1. This comment has been removed by the author.

    ReplyDelete
    Replies
    1. Hey bro sorry for late reply but can you please write a previous comment

      Delete