Saturday, October 28, 2017

Object Oriented Programming



History of C++


 History of c++ OR What is c++?
o      C++ is object oriented language. It was found in year 1980.
o      It was made by Bjarne Stroustrup at AT & T Bell lab, NJ, USA.
o      C++ contains power of c language as well as it supports object oriented programming features.
o      So c++ is extended c language with classes, so initially c++ was  called as ‘C with classes’.
o      However later in 1983 name was changed to c++.
o      The idea of c++ language is comes from ++ operator of c language, so named given as c++ which suggesting that it is increment version of c.
o      During the early 1990s the language underwent a number of improvements and changes.
o      These changes were made fixed by ANSI / ISO standards committee in November 1997.  It also added several new features to it.
o      C++ is a super set of c. Therefore all C programs are also C++ programs.
o      However there are some minor difference between c and c++.
o      C++ adds some good features that c does not have like classes, inheritance, function overloading, operator overloading etc.
o      C provides us top – down programming while C++ provides us bottom – up programming.

Difference between POP & OOP


No
Procedure oriented programming (POP)
Object oriented programming (OOP)
1
POP emphasis on algorithms (procedure)
OOP emphasis on data rather than procedure.
2
Large programs are divided into smaller programs known as functions.
Programs are divided into objects.
3
They have not facility to hide data.
They have facility to hide data from outside world.
4
Function can transfer data from one function to another and one form to another form.
Objects can communication with each other using functions.
5
It does not have powerful features like operator overloading, inheritance etc.
It contains powerful features like operator overloading, inheritance.
6
For design program it uses top-down approach.
For design program it uses bottom-up approach.
7
Examples: C, COBOL, FORTRAN etc.
Examples: C++

Objects

OBJECT: 
o     Objects are basic runtime entity in object oriented system. 
o      Objects may be a pen, a person, a table etc.
o      Objects may define user define data types like time, vectors etc.
o      Programming problems analyzed in terms of objects.
o      Object should be chosen such that they match closely with real world objects.
o      Objects required memory space for storage just like structure of ‘C’ language.
o      One object can send message to another objects.
o      For example student and record are two objects and student object may send request to record object for marks, then record object send marks for particular student.
o      Object can interact with each other without having knowledge about data and code of each other’s.
o      Following are ways to represents an object.

Class

Classes:
o      Classes are user defined data types and it behaves like built in types of programming language.


o      Object contains code and data which can be made user define type using class.


o      Objects are variables of class.


o      Once a class has been defined we can create any number of objects for that class. A class is collections of objects of similar type.


o      We can create object of class using following syntax,


Syntax:   class-name object-name;


o      Here class name is class which is already created. Object name is any user define name. For example, if student is class,


Example: student s1, s2;


o      In example s1 and s2 are name of objects for class student. We can create any number of objects for class.

Encapsulation

Encapsulation:
o      Combine data and functions into a single unit (called class) known as encapsulation.
o      Encapsulation is most important features of class. By which we can combine data and functions in one unit.
o      Using encapsulation we can hide data from outside world.
o      To hide data from direct access by program is known as data hiding or information hiding.

Data Abstraction

Data Abstraction:
o      Abstraction refers representation of necessary features without including more details or explanations.
o      Classes use the concept of abstraction.
o      Classes define list of abstract attributes like height, weight etc.
o      These attributes are sometimes called data members because they hold information. The functions that operate on these data are sometimes called methods or member functions.
o      Since classes use the concept of data abstraction, they are known as Abstract Data Types (ADT).