2. CPP-OOPS Concepts

CPP-Introduction: Previous                                                          Next: CPP-Statements
What is OOPS?
OOPS treats data as critical factor, and doesn’t allow the data to move around the system. It means OOPS tries to protect data. OOPS divides the problem into objects. Objects contains data and functions together. The whole responsibility is divided into objects or we can say that objects interacts with each other without affecting the data stored in them. Only functions of objects can access the function of another objects.
Structure of OOPS:

Characteristics of Object Oriented Programming are:
  • It gives importance to data rather than procedure or functions.
  • Programs are divided into Objects rather than functions.
  • Data is protected and can`t accessed easily.
  • Objects only interact with each other to accomplish a tasks.
  • Solves the problem of real world.
  • It based on Bottom-Up approach.
Difference between OOPS and POP:
OOPS                                                                      POP
  1. It uses top-down approach.                                           It uses Bottom-Up approach.
  2. It solves real world problem.                                         Can`t solve the real world problem.
  3. The program is divided into Objects.                           The program is divided into Functions.
  4. Gives security of data stored in Objects.                      No security. Global data can be accessed easily.

Basic concept of OOPIt includes:-
  1. Objects
  2. Classes
  3. Data Abstraction and Encapsulation
  4. Inheritance
  5. Polymorphism
  6. Data Binding
  7. Message Passing
A. Objects: Object is an essential element of OOPS paradigm. Object is an Entity, an entity can be defined thing having some attributes or characteristics and existed in real world. Entity can be Person, Student, Fanetc.
Objects are run time entity and stores or bound the data or functions together in it. Data or variable stored in object represents the features or characteristics of an Objects and functions defines what action is to be done on the objects.
Eg:-         Person is an Object.
Variables or data are:
Name of Person
Id of a Person
Date of Birth, Address of a person
Functions are:
Working
Talking etc.

Eg:           Scale:
Variables are:           Size, Color, product_id.
Functions are:          Measure, Draw lines

Objects always takes a memory space. Objects are totally dependent on class or template.
Syntax:    ;
Eg:           Student std;
B. Classes: A class is a Blueprint, which doesn't exists or can`t work independently. The entire data or function stored in objects are defined accordingly the class. Classes are collection of variables and functions. Variables of classes are known as member functions. Classes are used to declare objects of that class. More than one object of a class can be created.
For Eg: Fruit is a class and Mango, banana, apples oranges are objects of fruit class.
Syntax:
class
{
;
;
};
Definition of class is always enclosed or end with the semicolon. [;]
C. Data Abstraction and Encapsulation: the term Abstraction refers to act of representing an essential features without knowing the background details. The real world example is Switchboard. Switchboard totally contains buttons. In which we press button according to our requirements, what is happening inside, how the buttons are working we need not to know about it.Classes uses Data Abstraction and a classes which uses Data Abstraction is known as Abstract data type because classes are also a data type which is user defined.
Encapsulation: the act of binding both data and functions into a single unit or single class is known as Encapsulation. Encapsulation defines the security of the variable or data stored in class. It doesn’t allow the data to move around and not make them accessible to the outside world.
D. Inheritance: this feature provides the reusability. The term inheritance defines the hierarchical structure. Inheritance is process of creating a new class by using the data member or member functions of existing class.
Two mainly terms are used in inheritance:
  1. Parent class/Super class: the existing class, which giving its feature is known as parent class or super class.
  2. Child class/Sub class: a class which taking the features of existing class is known as subclass.
Eg:

E. Polymorphism: It is a Greek word which means multiple forms, or we can say that single name having a multiple images. The polymorphism allows programmer to make a function in a class and provides a facility to make same function with same name in another class with different functionality. The main thing is to be remember is the signature or parameters used in both functions. Parameters must be different.
And difference can be in:-
a. Number of parameter to be passed.
b. The sequence of parameter.
c. Data types of the parameters passed.
F. Dynamic Binding: it refers to create a link of a procedure call to code executed every procedure needs a link to create between its code or definition and function or procedure name.
G. Message Passing: when a program is executed the object communicates with each other by sending a message to each other. Message contains the information to send or receive.
The message passing process contains:
  1. Name of object.
  2. Name of message.
  3. Information that is to be passed.
Benefits of OOP: -
  • It takes care of data and ensure the security of data stored in object.
  • Provides reusability through inheritance.
  • Redundant code can be removed.
  • Objects provides easy and flexibility in work.
  • Member functions can be easily removed or inserted.
  • Complexity of software can be easily managed.
Applications of OOPS:-
  • CAD/CAM system.
  • Real time system.
  • AI system
  • Expert system.
  • OOPS based database.
CPP-Introduction: Previous                                                          Next: CPP-Statements