UNIT -1Concepts of Object Oriented programming: Object oriented paradigm-differences betweenObject Oriented Programming and Procedure oriented programming, Basic concepts of ObjectOriented Programming,Encapsulation, Inheritance and Polymorphism. Benefits of OOP .Structureof a C++ program, namespace, Data types, C++ tokens, identifiers, variables, constants, operators,control structures & loops.
Overview of C language:
1.C language is known as structure oriented language or procedure oriented language
2.Employs top-down programming approach where a problem is viewed as a sequence of tasks to be performed.
3.All program code of c can be executed in C++ but converse many not be possible
4. Function overloading and operator overloading are not possible.
5. Local variables can be declared only at the beginning of the block.
6. Program controls are through jumps and calls to subroutines.
7.Polymorphism, encapsulation and inheritance are not possible.
For solving the problems, the problem is divided into a number of modules. Each module is a subprogram.
8. Data abstraction property is not supported by procedure oriented language.
9. Data in procedure oriented language is open and can be accessed by any function.
Overview of C++ language:
1. C++ can be considered as an incremental version of c language which consists all programminglanguage constructs with newly added features of object oriented programming.
2.c++ is structure(procedure) oriented and object oriented programming language.
3.The file extension of C++ program is .CPP
4. Function overloading and operator overloading are possible.
5. Variables can be declared in inline i.e when required
6. In c++ more emphasis is give on data rather than procedures
7.Polymorphism, encapsulation and inheritance are possible.
8. Data abstraction property is supported by c++.
9. Data access is limited. It can be accessed by providing various visibility modes both for dataand member functions. there by providing data security by data hiding
10.Dymanic binding is supported by C++
11..It supports all features of c language
12.It can be called as an incremental version of c language
Difference Between Procedure Oriented Programming (POP) & Object Oriented Programming (OOP)
Procedure Oriented Programming1
program is divided into small partscalled functions.
Importance is not given to data but to 2functions as well as sequence of
actions to be done.
3follows
Top Down approach.4It does not have any access specifier.
5
Data can move freely fromfunction to function in the system.
Object Oriented Programmingprogram is divided into parts called
objects.
Importance is given to the data rather thanprocedures or functions because it worksas a real world.
OOP follows Bottom Up approach.OOP has access specifiers named
Public, Private, Protected, etc.
objects can move and communicate with each other through member functions.6
To add new data and function in POP is notso easy.
Most function uses Global data for sharing7that can be accessed freely from function to
function in the system.
It does not have any proper way for hiding8data so it is
less secure.
9Overloading is not possible.OOP provides an easy way to add new dataand function.
In OOP, data can not move easily fromfunction to function,it can be kept public orprivate so we can control the access of data.OOP provides Data Hiding so provides moresecurity.
In OOP, overloading is possible in the form ofFunction Overloading and Operator
Overloading.
Example of Procedure Oriented10Programming are : C, VB, FORTRAN,
Pascal.
Example of Object Oriented Programming are :C++, JAVA, VB.NET, C#.NET.
Principles( or features) of object oriented programming:
1.Encapsulation
2.Data abstraction
3.Polymorphism
4.Inheritance
5.Dynamic binding
6.Message passing
Encapsulation: Wrapping of data and functions together as a single unit is known as encapsulation. Bydefault data is not accessible to outside world and they are only accessible through the functions which arewrapped in a class. prevention of data direct access by the program is called data hiding or informationhiding
Data abstraction :Abstraction refers to the act of representing essential features without including theback ground details or explanation. Classes use the concept of abstraction and are defined as a list of attributes such as size, weight, cost and functions to operate on these attributes. They encapsulate allessential properties of the object that are to be created. The attributes are called as data members as theyhold data and the functions which operate on these data are called as member functions.
Class use the concept of data abstraction so they are called
abstract data type (ADT)
Polymorphism: Polymorphism comes from the Greek words poly and morphism. poly meansmany and morphism means form i.e.. many forms. Polymorphism means the ability to take more thanone form. For example, an operation have different behavior in different instances. The behavior dependsupon the type of the data used in the operation.
Different ways to achieving polymorphism in C++ program:
1)Function overloading 2) Operator overloading
#include
using namespace
std; int main()
{int a=4; a=a<<2;
cout<<
return 0;
}
Inheritance: Inheritance is the process by which one object can acquire the properties of another.
Inheritance is the most promising concept of OOP, which helps realize the goal of constructing softwarefrom reusable parts, rather than hand coding every system from scratch. Inheritance not only supportsreuse across systems, but also directly facilitates extensibility within a system. Inheritance coupled withpolymorphism and dynamic binding minimizes the amount of existing code to be modified whileenhancing a system.
When the class child, inherits the class parent, the class child is referred to as derived class (subclass) and the class parent as a base class (super class). In this case, the class child has two parts: a derivedpart and an incremental part. The derived part is inherited from the class parent. The incremental part isthe new code written specifically for the class child.
Dynamic binding:
Binding refers to linking of procedure call to the code to be executed in response to the call.Dynamic binding(or late binding) means the code associated with a given procedure call in not knownuntil the time of call at run time.
Message passing:
An object oriented program consists of set of object that communicate with each other.
Objects communicates with each other by sending and receiving information .A message for an object is a request for execution of a procedure and there fore invoke
the function that is called for an object and generates result
Benefits of object oriented programming (OOPs)Reusability: In OOP s programs functions and modules that are written by a user can be reused by
other users without any modification.
Inheritance: Through this we can eliminate redundant code and extend the use of existing classes.
Data Hiding: The programmer can hide the data and functions in a class from other classes. It helps the programmer tobuild the secure programs.
Reduced complexity of a problem: The given problem can be viewed as a collection of different objects. Each object is responsible for a specific task. The problem is solved by interfacing the objects. This technique reduces the
Next page