Вы находитесь на странице: 1из 4

C++ Programming & DBMS Introduction to OOPs

Introduction to OOPs
1. Procedure oriented programming approach.

A procedure oriented language such as C, Pascal, COBOL, etc. consists of a


set of statements. Each statement asks the computer to do something like read data,
print data, branch to loop, etc.
A program in a procedure language is a list of instructions. For every small
program the above organizing principle is sufficient. The programmer creates the list
of instructions and computer carries them out. But, we get into difficulties when the
program becomes large.

Characteristics of Procedure Oriented Languages:

1. Modular approach/modular design:


When program become larger, the single unit of instruction becomes unwieldy.
A program is divided into number of functions, each function has a clearly defined
purpose and closely defined interfaces to the other function in the program. Dividing
a program into functions or modules is one of the characteristics of structured
programming.

Main Program

Function -1 Function-2 Function-3

Function-4 Function-5

2. Data undervalued or Poor data protections:


In procedural languages, more emphasis is on statements or functions. Data
are not given prominence that they deserve. This fact gives rise to the following
problems. Many procedural languages support global and local variables. Global
variables are those which can be accessed by all functions and local variables are
declared within functions and they are accessible to only those functions in which
they are declared.

Local variables have limited use. It is very difficult to keep track of which
function has changed the values of which variables. Another problem with this
approach is that if we need to add any new data to the program, all the functions
which access the data should be modified. This may provide room for errors to creep
in.

II Sem BCA 1 Sree Siddaganga College for Women, Tumkur


C++ Programming & DBMS Introduction to OOPs

Global Data-1 Global Data-2


The basic trouble with this procedural language is that the data is opened to
any part of the program. This is something like keeping your valuable personal
documents where anybody can access. They can either accidently or will fully change
the document and causes irreparable damages. This is precisely what can happen to
the data kept in global form.
Function -1 -2 data, but data canFunction -3
“A program has no existence without
Function exist without a program.”
So, any methodology that gives primary importance to data must be very closer to
the real world entity.
Local Data Local Data Local Data
3. New data type:
Being able to create your own data types using existing data type without
altering is called Data extensibility.

Traditional programming languages are not usually extensible without actual


conversion. You can’t bundle X and Y co-ordinates into a single variable called point
and then add or subtract values of this type. If we try to do the above it becomes
more complex to write the program and maintain. In other words a traditional
language allows the user to create the new data type using the structure.

Object Oriented Programming


“Object Oriented Programming is a method of implementation in which programs are
organized as cooperative collections of objects, each of which represents an instance of
same class”.

Salient features of OOPs:

1. Class and Object: A Class represents a set of objects that shares common
characteristics and behavior or A Class is an overall organization of data and
operational method.
An object is a real world entity / real world identifiable entity which represent
characteristics, state and behavior. In other words, Object is a variable of type
class or object is an instance, which represents the characteristics of a class.
e.g. Vehicle is a class, Car is an object.
Furniture is a class, table is an object.
2. Data abstraction: Abstraction refers to the act of representing essential features
without including the background details / explanation. Abstraction is the concept
of simplifying a real world concept into its essential elements.
e.g. To define an abstract STACK class using abstract representation:
Class : STACK
Data : St [20], top
Methods : 1. Pre-Condition: isEmpty (), isFull ()
2. Functions: PUSH (), POP ()
Abstract class represents only the external structure of the class but not the
internal structure.
3. Data Encapsulation and hiding: The wrapping up of data and method into a single
unit is known as Encapsulation. The data is not accessible to the outside world and

II Sem BCA 2 Sree Siddaganga College for Women, Tumkur


C++ Programming & DBMS Introduction to OOPs

only those methods, which are wrapped in the class, can access it. These
methods provide the interface between the object data and the program.
This insulation of the data from direct access by the program is called Data
hiding.
Encapsulation is a way to implement data abstraction. Encapsulation hides the
details of the implementation of an object.
4. Polymorphism: Polymorphism means the ability to take more than one form. An
operation may exhibit different behavior in different instance. The behavior
depends upon the type of data used in the operation. A function name can be
used to handle different types of arguments. This is similar to a particular word
having different meanings depending on the context. Polymorphism is extensively
used in implementing inheritance.
5. Inheritance: Inheritance is the process by which objects of one class acquire the
properties of object of another class. In OOP, the concept of inheritance provides
the idea of reusability. This means that we can add additional features to an
existing class without modifying it. This is possible by deriving a new class form
the existing one. The new class will have the combined features of both the
classes. It represents parent–child relationship or hierarchical model.

6. Message passing: An OOP consists of a set of objects that communicates with


each other. It includes the following basic steps,
a. Creating a class that define objects and their behavior
b. Creating an object from class definition.
c. Establishing communication among objects

Message passing involves specifying the name of the object, name of the
method and the information to be sent.

E.g. emp.totalSalary (Employee p);


Where emp is an object, totalSalary is a method and Employee p is a message.

7. Dynamic Binding: Binding refers to the linking of a procedure call to the code to
be executed in response to the call. The dynamic binding means, the code
associated with a given procedure call is not known until the time of call at runtime. It is
associated with polymorphism and inheritance. A procedure call associated with a
polymorphic reference depends on the dynamic type of that reference.
8. Bottom-up approach: OOPs follows the bottom-up approach for coding and top-
down approach for design. It reduces the compilation time and debugging time.
Bottom-up approach follows the user to develop a unit module first, then
integrates all unit module into a single main module.

Example for OOPs languages are C++, JAVA, Visual Basic, Visual C++ etc.,

Advantages of Object Oriented Programming


 Simplicity: Software models are real object models in the application domain.
The complexity of the program is reduced and the program structure becomes
clear and simple.
 Modularity: Each object forms a separate entity with internal workings that
are decoupled from other parts of the system.

II Sem BCA 3 Sree Siddaganga College for Women, Tumkur


C++ Programming & DBMS Introduction to OOPs

 Modifiability: It is easy to make minor changes in the data representation.


Changes within an object do not affect any other part of the program provided
that the external behaviour of the object is preserved.
 Extensibility: Adding new features to the existing object.
 Flexibility: It is very flexible in accommodating different situations because
the interaction patterns among the objects can be changed without modifying
the objects.
 Maintainability: Objects can be maintained separately, locating and fixing
problems easy.
 Code Reusability: This means that we can add additional features to an
existing class without modifying it. This is possible by deriving a new class
form the existing one. The new class will have the combined features of both
the classes.

Disadvantages
 It does not have functional abstraction.
 There is still a lot of discussion about which features are really essential to
Object-Orientedness.
 Lack of solid formal foundations.

Review Questions

1. What are the limitations of the procedural programming technique?


2. What are the salient features of OOPs?
3. What is Object-Oriented programming? Describe its benefits in brief.
4. Explain each of the following in about 3 sentences.
a. Encapsulation
b. Inheritance
c. Polymorphism
5. Explain any 3 advantages of OOPs.

II Sem BCA 4 Sree Siddaganga College for Women, Tumkur

Вам также может понравиться