Overview of OOPS
Overview of OOPS
NEED OF OPP
OPP is an approach to program organization and development that attempts to
eliminate some of the pitfalls of conventional programming methods by incorporating the
best of structured programming features with several powerful new concepts. It is a new way
of organizing and developing programs and has nothing to do with any particular language.
CHARACTERISTICS OF POP
1. Emphasis is on doing things (algorithm)
2. Large programs are divided into smaller programs known as functions.
3. Most of the function share global data.
4. Data move openly around the system from function to function.
5. Function transform data from one form to another.
6. Employs top-down approach in program design.
FEATURES OF OOP
1. Emphasis is on data rather than procedure.
2. Programs are divided into 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 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.
CHARACTERISTICS OF OOPS
OBJECTS
Objects are the basic runtime 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. Objects take up
space in the memory and have an associated address.
When a program is executed, the object interact by sending message to one another.
For e.g. if “customer” and “account” are two object in a program, then the customer object
may sent a message to the account object requesting for the bank balance. Each object
contains data and code to manipulate the data. Objects can interact without having to know
details of each other’s data or code. It is sufficient to know the type of message accepted and
the type of response return by the objects.
CLASSES
The entire set of data and code of an object can be made a user defined data type with
the help of a class. In facts, 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 thus is a collection
of objects of similar type.
For e.g. mango, apple and orange are the members of class fruit. Classes are user defined data
type and behaves like the built in types of a programming language.
If fruit has been defined as a class, then the statement
Fruit mango;
Will create an object mango belonging to class fruit.
e.g. When an engineer needs to add a resistor to the device she is creating, she doesn’t
typically build a new one from scratch. She walks over to a bin of resistors, examines the
colored bands that indicate the properties, and picks the one she needs. The resistor is a
“black box” as far as the engineer is concerned—she doesn’t much care how it does its work
as long as it conforms to her specifications; she doesn’t need to look inside the box to use it
in her design.
Similarly, when the engineer uses the resistor, she need not know anything about the
internal state of the resistor. All the properties of the resistor are encapsulated in the resistor
object; they are not spread out through the circuitry. It is not necessary to understand how the
resistor works to use it effectively. Its data is hidden inside the resistor’s casing.
INHERITANCE
Inheritance is the process by which objects of one class acquires the properties of
objects of another class. It supports the concept of hierarchical. For e.g. the word “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.
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 from the existing one. The new class will have the combined features of
both the classes.
e.g. When the engineers at Acme Motors want to build a new car, they have two
choices: They can start from scratch, or they can modify an existing model. Perhaps their Star
model is nearly perfect, but they’d like to add a turbocharger and a six-speed transmission.
The chief engineer would prefer not to start from the ground up, but rather to say, “Let’s
build another Star, but let’s add these additional capabilities. We’ll call the new model a
Quasar.” A Quasar is a kind of Star, but a specialized one with new features.
C++ supports inheritance. A new type, which is an extension of an existing type, can
be declared. This new subclass is said to derive from the existing type and is sometimes
called a derived type.
POLYMORPHISM
Polymorphism is another important OOP concept. Polymorphism, a Greek term
means the ability to take more than one form. An operation may exhibit different behaviors in
different instances. The behavior depends on the types of data used in the operation. For e.g.
consider the operation of addition for two numbers, the operation will generate a sum and if
the operands are string, then the operation would produce a third string by concatenation.
The process of making an operator to exhibit different behavior in different instances
is known as Operator Overloading. An Object Oriented Program consists of a set of objects
that communicate with each other. The process of programming in an object-oriented
language, therefore involves the following basic steps :-
1. Creating classes that define objects and their behavior.
2. Creating objects from class definitions &
3. Establishing communication among objects.
e.g. The new Quasar might respond differently than a Star does when you press down on
the accelerator. The Quasar might engage fuel injection and a turbocharger, whereas the Star
would simply let gasoline into its carburetor. A user, however, does not have to know about
these differences. He can just “floor it,” and the right thing will happen, depending on which
car he’s driving.
C++ supports the idea that different objects do “the right thing” through what is called
function polymorphism and class polymorphism. Poly means many, and morph means form.
Polymorphism refers to the same name taking many forms.
ADVANTAGES OF OOPS
1. Through inheritance we can eliminate redundant code and extend the use of
existing.
2. Classes
3. We cab build programs from the standard working modules that communicate
with one another. This leads to savings of development time and higher
productivity.
4. The principle of data hiding helps the programmer to build secure programs that
cannot be invaded by code in other part of program.
5. It is possible to have multiple instances of an object to co-exist without any
interference.
6. It is easy to partition the work in a project based on object.
7. OOPs systems can be easily upgraded from small to large systems.
8. Message passing techniques is much simpler.
9. Software complexity can be easily managed.
APPLICATIONS OF OOP
The promising areas for application of OOP include :-
1. Real time systems
2. Simulations and Modeling.
3. Object oriented databases.
4. Hypertext, Hypermedia and expert text.
5. Artificial Intelligence and Expert System.
6. Neural Networks and parallel programming.
7. Decision support and office automation systems.
8. CIM / CAD / CAM systems.