Oops

Tabular array OF CONTENT:

  1. Introduction
  2. Form
  3. Objects
  4. Encapsulation
  5. Abstraction
  6. Polymorphism
  7. Inheritance
  8. Dynamic Binding
  9. Bulletin Passing

Object-oriented programming – Every bit the name suggests uses objects in programming. Object-oriented programming aims to implement existent-globe entities like inheritance, hiding, polymorphism, etc in programming. The primary aim of OOP is to bind together the data and the functions that operate on them so that no other function of the code can access this data except that part.

Characteristics of an Object Oriented Programming language

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 ain information members and member functions, which can be accessed and used by creating an case of that grade. A class is like a pattern for an object.

For Example: Consider the Grade of Cars. There may exist many cars with unlike names and brand but all of them will share some common properties similar all of them will take 4 wheels, Speed Limit, Mileage range etc. So here, Automobile is the grade and wheels, speed limits, mileage are their backdrop.

  • A Form is a user-divers data-blazon which has data members and member functions.
  • Data members are the data variables and member functions are the functions used to manipulate these variables and together these data members and member functions ascertain the properties and behaviour of the objects in a Class.
  • In the to a higher place example of class Car, the data member will be speed limit, mileage etc and member functions tin can apply brakes, increase speed etc.

We can say that a Class in C++ is a bluish-impress representing a group of objects which shares some mutual properties and behaviours.

Object: An Object is an identifiable entity with some characteristics and behaviour. An Object is an example of a Grade. When a grade is defined, no retention is allocated but when it is instantiated (i.eastward. an object is created) retentivity is allocated.

class person

{

char name[20];

int id;

public :

void getdetails(){}

};

int master()

{

person p1;

}

Object take upwards space in retention and have an associated address like a record in pascal or structure or marriage in C.

When a program is executed the objects interact by sending messages to one some other.

Each object contains information and lawmaking to manipulate the data. Objects can collaborate without having to know details of each other's data or code, information technology is sufficient to know the type of message accepted and blazon of response returned by the objects.

Encapsulation: In normal terms, Encapsulation is divers as wrapping up of data and information nether a single unit. In Object-Oriented Programming, Encapsulation is defined as binding together the data and the functions that manipulate them.

Consider a real-life example of encapsulation, in a company, there are different sections like the accounts department, finance section, sales department etc. The finance department handles all the financial transactions and keeps records of all the data related to finance. Similarly, the sales section handles all the sales-related activities and keeps records of all the sales. Now at that place may arise a situation when for some reason an official from the finance section needs all the information about sales in a item calendar month. In this case, he is not allowed to directly access the information of the sales section. He will first take to contact some other officer 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 unmarried name "sales section".

Encapsulation in C++

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

Abstraction: Data brainchild is one of the most essential and important features of object-oriented programming in C++. Abstraction means displaying only essential information and hiding the details. Information abstraction refers to providing just essential information well-nigh the information to the outside world, hiding the groundwork details or implementation.

Consider a existent-life case of a man driving a automobile. The man merely knows that pressing the accelerators volition increase the speed of the car or applying brakes will cease the automobile simply he does non know near how on pressing accelerator the speed is really increasing, he does not know about the inner mechanism of the car or the implementation of accelerator, brakes etc in the machine. This is what brainchild is.

  • Brainchild using Classes: We tin can implement Abstraction in C++ using classes. The class helps united states of america to grouping data members and fellow member functions using available access specifiers. A Course tin can decide which data member will be visible to the outside world and which is not.
  • Abstraction in Header files: One more than type of abstraction in C++ tin can be header files. For example, consider the pw() method present in math.h header file. Whenever we need to calculate the power of a number, we only phone call the function pow() nowadays in the math.h header file and pass the numbers as arguments without knowing the underlying algorithm co-ordinate to which the office is actually computing the ability of numbers.

Polymorphism: The word polymorphism means having many forms. In simple words, we tin define polymorphism as the power of a message to be displayed in more than one form.

A person at the same time can have different characteristic. Similar a human at the same time is a father, a husband, an employee. So the same person posses different behaviour in different situations. This is called polymorphism.

An operation may exhibit different behaviours in unlike instances. The behaviour 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 exhibit unlike behaviours in different instances is known as operator overloading.
  • Function Overloading: Function overloading is using a unmarried function name to perform dissimilar types of tasks.
    Polymorphism is extensively used in implementing inheritance.

Example: Suppose we have to write a function to add some integers, some times there are ii integers, some times there are 3 integers. We can write the Add-on Method with the same name having different parameters, the concerned method will exist chosen according to parameters.

Inheritance: The capability of a class to derive properties and characteristics from another class is called Inheritance. Inheritance is one of the most important features of Object-Oriented Programming.

  • Sub Class: The form that inherits properties from another class is chosen Sub class or Derived Form.
  • Super Class:The class whose properties are inherited past sub class is called Base Class or Super course.
  • Reusability: Inheritance supports the concept of "reusability", i.east. when we want to create a new grade and at that place is already a class that includes some of the lawmaking that we want, nosotros can derive our new class from the existing class. By doing this, we are reusing the fields and methods of the existing class.

Instance: Domestic dog, Cat, Cow tin be Derived Form of Animate being Base Class.

Dynamic Binding: In dynamic binding, the lawmaking to be executed in response to function telephone call is decided at runtime. C++ has virtual functions to support this.

Message Passing: Objects communicate with one another past sending and receiving information to each other. A bulletin for an object is a request for execution of a procedure and therefore will invoke a function in the receiving object that generates the desired results. Message passing involves specifying the name of the object, the proper name of the function and the data to be sent.

Related Articles:

  • Classes and Objects
  • Inheritance
  • Access Modifiers
  • Abstraction

This article is contributed by Vankayala Karunakar. Please write comments if you find anything wrong, or y'all desire to share more than information about the topic discussed higher up.


pollardhenow1948.blogspot.com

Source: https://www.geeksforgeeks.org/object-oriented-programming-in-cpp/

0 Response to "Oops"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel