1.Object Orientation Programming
1.Object Orientation Programming
Programming
Prof. Tejashree V. Pawar
Cummins College of Engineering
Pune
1
Agenda
1. Software Crisis
2. Software Evolution
3. Difference between Procedure-Oriented and Object-Oriented Programming
4. Basic concept of OOP
5. Benefits of OOP
6. Object-Oriented languages
7. Application of OOP
2
Software Crisis
● Development in software technology continue to be dynamic.
● New tools and techniques
● Designing become critical in view of the increasing complexity of
software system as well as the highly competitive nature of industry.
● The following issues need to be addressed to face this crisis:
○ How to represent real-life entities of problem in system design?
○ How to design systems with open interfaces?
○ How to ensure re-usability and extensibility of module?
○ How to develop modules that are tolerant to any changes in future?
○ How to improve software productivity and decrease software cost?
○ How to improve the quality of software and manage time schedules?
○ How to industrialize the software development process?
3
Many software products either not finished, or not used, or else are delivered with
major errors.[Fig.1.1]
1. Correctness
2. Maintainability
3. Reusability
4. Openness and interoperability
5. Portability
6. Security
7. Integrity
8. User friendliness
6
Software Evolution
7
Software Evolution continued...
C language- structure programming:
8
Procedure-Oriented
Programming
Vs
Object-Oriented Programming
9
Procedure-Oriented Programming
Procedure-Oriented Programming (POP)- COBOL,
FORTRAN and C.(Read, calculate and print)
● It consists of writing a list of instructions(or actions) for
the computer to follow and organizing these instructions
into group known as functions.
● It represent flow of control from one action to another.
● Concentrate on the development of functions, then given
data that are being used by various functions.
10
11
12
Procedure-Oriented Programming
● Global data- change by a function.
● In large program - very difficult to identify what data is used by
which function.
● So, we need to revise data structure and all functions that
access the data. This provide an opportunity for bugs to creep
in.
● Another problem- it does not model real world problems very
well because functions are action-oriented and do not really
correspond to the element of the problem.
13
Characteristics by procedure-oriented prog.
14
Object-Oriented programming
● Motivation- to remove some of the flaws encountered in POP.
● OOP treats data as a critical element in the program
development and does not allow it to flow freely around the
system.
● It ties data more closely to the functions that operate on it and
protects it from accidental modification from outside functions.
● OOP allows decomposition of a problem into a number of
entities called objects and then builds data and functions
around these objects.
15
16
Features of Object-Oriented
programming
1. Emphasis on data rather than procedure.
2. Programs are divided into what are known as objects.
3. Data structures are designed such that they characterize the objects.
4. Functions that operate on the data of an object are tied together in the data
structure.
5. Data is hidden and cannot be accessed by external functions.
6. Objects may communicate with each other through functions.
7. New data and functions can be easily added whenever necessary.
8. Follows bottom-up approach in program design.
17
Definition of OOP:
“ Object-Oriented programming as an approach that provides a way of
modularizing program by creating partitioned memory area for both data and
functions that can be used as templates for creating copies of such module on
demand”.
18
Basic concepts of OOP
1. Objects
2. Classes
3. Data abstraction and encapsulation
4. Inheritance
5. Polymorphism
6. Dynamic binding
7. Message passing
19
1. Objects :
● Objects are the basic run-time entities.
● They may represents a person, a place, a bank account, a table of data or any
item that program has to handle. They may also represent user-defined data
such as vectors, time and lists.
● Programming problem is analyzed in terms of objects and the nature of
communication between them.
● Program objects should be chosen that they match closely with the real-world
objects.
● Objects take up space in the memory and have associated address like a
record in Pascal, or a structure in C.
● When program is executed, the objects interact by sending messages to one
another.
20
1. Objects contd...
● Each object contains data, and the code to manipulate the data.
● Objects can interact without having to know detail of each other’s data or code. It
is sufficient to know the type of the message accepted, and the type of response
returned by the objects.
21
2. Classes :
● The entire set of data and code of an object can be made a user-defined data
type with help of a class.
● In fact, objects are variables of the type class.
● Once class has been defined, we can create any number of objects belonging
to that class.
● Each object is associated with the data of type class with which they are
created.
● A class is thus a collection of objects of similar type.
● For example, mango, apple and orange are members of the class fruit.
● Classes are user-defined data types and behave like the built-in types of
programming language.
22
3. Data Abstraction and Encapsulation
Encapsulation:
● The wrapping of data and functions into a single unit( called class) is known as
encapsulation.
● The data is not accessible to the outside world, and only those functions which
are wrapped in the class can access it.
● These functions provide the interface between the object’s data and the
program.
● This insulation of the data from direct access by the program is called data
hiding or information hiding.
23
3. Data Abstraction and Encapsulation contd...
Abstraction:
● Abstraction refer to the act of representing essential features without
including the background details or explanations.
● Classes use the concept of abstraction and are defined as a list of abstract
attributes such as size, weight and cost, and functions to operate on these
attributes.
● The attributes some time called data members because they hold information.
● The functions that operate on these data are sometimes called methods or
member functions.
● Since classes use the concept of data abstraction, they are known as ADT.
24
4. Inheritance :
● Inheritance is the process by which objects of one class acquire the properties
of objects of another class.
● Supports the concept of hierarchical classification.
● The principle behind this sort of division is that each derived class shares
common characteristics with the class from which it is derived as shown in fig.
1.8
● Concept of inheritance provides the idea of reusability. This means we can
add additional features to an existing class without modifying it.
● This is possible by deriving a new class from the existing one.
● The new class will have the combined feature of both the classes.
25
26
5. Polymorphism :
● Polymorphism means the ability to take more than one form.
● An operation may exhibit different behaviors in different instances.
● The behavior depends upon the types of data used in the operation.
● The process of making an operator to exhibit different behaviors in different
instances is known as operator overloading.
● Fig. 1.9 shows that a single function name can be used to handle different
number and different types of arguments.
● Using the single function name to perform different types of tasks is known as
function overloading.
● Polymorphism allowing objects having different internal structures to share
the same external interface.
● It is extensively used in implementing inheritance.
27
28
6. Dynamic Binding (late binding):
29
7. Message Passing :
● An OOP consist of a set of objects that communicate with each other.
● The process of programming involves the following basic steps:
a. Creating classes that define objects and their behavior,
b. Creating objects from class definition, and
c. Establishing communication among objects.
● A message for an object is a request for execution of procedure, and therefore
will invoke a function (procedure) in the receiving object that generates the
desire result.
● Message passing involves specifying the name of the object, the name of the
function(message) and the information to be sent.
30
7. Message Passing :
Example,
31
Benefits of OOP :
● Offers benefits to both the program designer and the user.
● It contributes to the solution of many problems associated
with the development and quality of software products.
● It promises greater programmer productivity, better
quality of software and lesser maintenance cost.
32
Benefits of OOP continued...
The principal advantages are:
1. Through inheritance, we can eliminate redundant code and extend the use
existing classes.
2. We can build the program from the standard working modules that
communicate with one another, rather than having to start writing the code
from scratch. This leads to saving of development time and higher
productivity.
3. The principle of data hiding helps the programmer to build secure programs
that cannot be invaded by code in other parts of the program.
4. It is possible to have multiple instances of an object to co-exist without any
interference.
5. It is possible to map objects in the problem domain to those in the program.
33
Benefits of OOP continued...
6. It is easy to partition the work in a project based on objects.
7. The data-centered design approach enables us to capture more details of a
model in implementable form.
8. Object-oriented systems can be easily upgraded from small to large systems.
9. Message passing techniques for communication between objects makes the
interface descriptions with external systems much simpler.
10. Software complexity can be easily managed.
34
Object-oriented languages
OOP is classified into two categories:
Eg. Ada
● Data encapsulation
● Data hiding and access mechanisms
● Automatic initialization and clear-up of objects
● Operator overloading
35
Object-oriented languages...
Object-oriented programming:
36
Applications of OOP
● Real-time systems
● Simulation and modelling
● Object -oriented databases
● Hypertext, hypermedia and expertext
● Artificial Intelligence (AI) and expert system
● Neural networks and parallel programming
● Decision support and office automation system
● CIM / CAM / CAD systems
37