Chapter 1 OOPS
Chapter 1 OOPS
_____________________________________________________________________________________
Main program
Function - 4 Function -5
Function – 6
Function – 7 Function – 8
DRAWBACKS:
____________________________________________________________________________________
ASKS IT – S.Y.BSc IT Prof.Priyanka Shetty
1
Chapter – 1 Principles of Object- Oriented Programming July 23, 2010
_____________________________________________________________________________________
Another serious drawback is that it does not model real world problems
very well. This is because functions are action oriented and do not
really correspond to elements of the problem.
____________________________________________________________________________________
ASKS IT – S.Y.BSc IT Prof.Priyanka Shetty
2
Chapter – 1 Principles of Object- Oriented Programming July 23, 2010
_____________________________________________________________________________________
Object A Object
B
Data Data
Object C
Function
Data
Functions
Communication Functio
Fig 1.2 The organization of data and functions in object – oriented programs
Data structures are designed such that they characterize the objects.
Functions that operate on the data of an object are tied together in the
data structure.
____________________________________________________________________________________
ASKS IT – S.Y.BSc IT Prof.Priyanka Shetty
3
Chapter – 1 Principles of Object- Oriented Programming July 23, 2010
_____________________________________________________________________________________
Objects
Classes
Inheritance
Polymorphism
Dynamic binding
Message passing
1.3.1 Objects
Objects are the basic run time entities in an object – oriented system. They
may represent a person, a place , a bank account, a table of data or any item
that the 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 such that they match closely with the real – world objects.
Objects take up space in the memory and have an associated address like a
record in Pascal or a structure in C.
____________________________________________________________________________________
ASKS IT – S.Y.BSc IT Prof.Priyanka Shetty
4
Chapter – 1 Principles of Object- Oriented Programming July 23, 2010
_____________________________________________________________________________________
1.3.2 Classes
We just mentioned that objects can contain data, and code to manipulate
that data. The entire set of data and code of an object can be made a user –
defined data type with the help of a class. Infact objects are variables of the
type class. Once a 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
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 a programming language. The syntax used is no different than the
syntax used to create an integer object in C. If fruit has been defined as a
class, then the statement
fruit mango;
____________________________________________________________________________________
ASKS IT – S.Y.BSc IT Prof.Priyanka Shetty
5
Chapter – 1 Principles of Object- Oriented Programming July 23, 2010
_____________________________________________________________________________________
int a;
Data encapsulation is the most striking feature of a class. 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.
Since the classes use the concept of data abstraction, they are known as
Abstract Data types (ADT).
1.3.5 Inheritance
Inheritance is the process by which objects of one class acquire the
properties of objects of another class. It supports the concept of hierarchial
classification. For example, the bird ‘robin’ is a part of the class ‘flying bird’
which is again a part of the class ‘bird’. The principle behind this sort of
division is that each derived class shares common characteristics with the
class from which it is derived as illustrated in fig 1.4.
____________________________________________________________________________________
ASKS IT – S.Y.BSc IT Prof.Priyanka Shetty
6
Chapter – 1 Principles of Object- Oriented Programming July 23, 2010
_____________________________________________________________________________________
The new class will have the combined features of both the classes. The real
appeal and power of the inheritance mechanism is that it allows the
programmer to reuse a class that is almost, but not exactly, what he wants,
and to tailor the class in such a way that it does not introduce any
undesirable side-effects into the rest of the classes.
Note that each sub-class defines only those features that are unique to it.
Without the use of classification, each class would explicitly include all its
features.
1.3.6 Polymorphism
Polymorphism is another important OOP concept. Polymorphism, a greek
term means ability to take more than one form. An operation may exhibit
____________________________________________________________________________________
ASKS IT – S.Y.BSc IT Prof.Priyanka Shetty
7
Chapter – 1 Principles of Object- Oriented Programming July 23, 2010
_____________________________________________________________________________________
Fig 1.5 illustrates that a single function name can be used to handle different
number and different types of arguments. This is something similar to a
particular word having several different meanings depending on the context.
Using a single function name to perform different types of tasks is known as
function overloading.
Shape
Draw ()
____________________________________________________________________________________
ASKS IT – S.Y.BSc IT Prof.Priyanka Shetty
8
Chapter – 1 Principles of Object- Oriented Programming July 23, 2010
_____________________________________________________________________________________
Consider the procedure “draw” in fig 1.5. By inheritance, every object will
have this procedure. Its algorithm is, however, unique to each object and so
the draw procedure will be redefined in each class that defines the object. At
run-time, the code matching the object under current reference will be
called.
Example:
Employee.salary(name)
Object Information
Message
____________________________________________________________________________________
ASKS IT – S.Y.BSc IT Prof.Priyanka Shetty
9
Chapter – 1 Principles of Object- Oriented Programming July 23, 2010
_____________________________________________________________________________________
1.5 Applications
The promising areas for application of OOP include:
____________________________________________________________________________________
ASKS IT – S.Y.BSc IT Prof.Priyanka Shetty
10
Chapter – 1 Principles of Object- Oriented Programming July 23, 2010
_____________________________________________________________________________________
Real-time systems
CIM/CAM/CAD systems.
____________________________________________________________________________________
ASKS IT – S.Y.BSc IT Prof.Priyanka Shetty
11