Unit I: Periods: 10
1. Basic Concepts of OOP,
2. Object Oriented Languages,
3. Applications of OOP,
4. Structure of C++ program.
5. Difference between Top down & bottom up language.
1. BASIC CONCEPTS OF OBJECTS ORIENTED PROGRAMMING
Objects
Classes
Data abstraction and encapsulation
Inheritance
Polymorphism
Dynamic binding
Message passing
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 must handle.
The fundamental idea behind object oriented approach is to combine both data and function into a
single unit and these units are called objects.
The term objects means a combination of data and program that represent some real word entity. For
example: consider an example named Amit; Amit is 25 years old and his salary is 2500. The Amit
may be represented in a computer program as an object. The data part of the object would be (name:
Amit, age: 25, salary: 2500)
The program part of the object may be collection of programs (retrive of data, change age,
change of salary). In general even any user –defined type-such as employee may be used. In the
Amit object the name, age and salary are called attributes of the object.
Object: Student STUDENT
DATA Total
Name
Date-of-birth
Marks Average
FUNCTIONS
Total
Average Display
Display
CLASS:
A group of objects that share common properties for data part and some program part are collectively called as
class.
In C ++ a class is a new data type that contains member variables and member functions that operate on the
variables.
DATA ABSTRACTION :
Abstraction refers to the act of representing essential features without including the back ground details or
explanations. Classes use the concept of abstraction and are defined as size, width and cost and functions to
operate on the attributes.
DATA ENCAPSALATION :
The wrapping up of data and function 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 objects data and the program.
INHERITENCE :
Inheritance is the process by which objects of one class acquire the properties of another class. In the concept
of inheritance provides the idea of reusablity. This mean that we can add additional features to an existing
class with out modifying it. This is possible by desining a new class will have the combined features of both
the classes.
POLYMORPHISIM:
Polymorphism means the ability to take more than one form. An operation may exhibit different instance. The
behaviour depends upon the type of data used in the operation.
A language feature that allows a function or operator to be given more than one definition. The types of
the arguments with which the function or operator is called determines which definition will be used.
Overloading may be operator overloading or function overloading.
It is able to express the operation of addition by a single operator say ‘+’. When this is possible you use the
expression x + y to denote the sum of x and y, for many different types of x and y; integers, float and complex
no. You can even define the + operation for two strings to mean the concatenation of the strings.
DYNAMIC BINDING :
Binding refers to the linking of a procedure call to the code to the executed in response to the call. Dynamic
binding means the code associated with a given procedure call is not known until the time of the call at run-
time. It is associated with a polymorphic reference depends upon the dynamic type of that reference.
PASSING :
An object oriented program consists of a set of objects that communicate with each other.
A message for an object is a request for execution of a procedure and therefore will invoke a function
(procedure) in the receiving object that generates the desired result. Message passing involves specifying the
name of the object, the name of the function (message) and information to be sent.
Employee . Salary (name)
Object Information
Message
2. Object Oriented Programing
“Object oriented programming as an approach that provides a way of modularizing programs by
creating partitioned memory area for both data and functions that can be used as templates for
creating copies of such modules on demand”.
Object A Object B
Data Data
Communication
Functions Functions
Object C
Functions
Data
Features of the Object Oriented programming
1. Emphasis is on doing 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 can’t be accessed by external functions.
6. Objects may communicate with each other through functions.
7. New data and functions can be easily added.
8. Follows bottom-up approach in program design.
BENEFITS OF OOP:
Oop offers several benefits to both the program designer and the user. Object-oriented contributes to
the solution of many problems associated with the development and quality of software products.
The principal advantages are :
1. Through inheritance we can eliminate redundant code and extend the use of existing
classes.
2. We can build programs 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. This principle of data hiding helps the programmer to build secure programs that can’t be
invaded by code in other parts of the program.
4. It is possible to have multiple instances of an object to co-exist with out any interference.
5. It is easy to partition the work in a project based on objects.
6. Object-oriented systems can be easily upgraded from small to large systems.
7. Message passing techniques for communication between objects makes the interface
description with external systems much simpler.
8. Software complexity can be easily managed.
3. APPLICATION OF OOP:
The most popular application of oops up to now, has been in the area of user interface design such as
windows. There are hundreds of windowing systems developed using oop techniques.
Real business systems are often much more complex and contain many more objects with
complicated attributes and methods. Oop is useful in this type of applications because it can simplify
a complex problem. The promising areas for application of oop includes.
1. Real – Time systems.
2. Simulation and modeling
3. Object oriented databases.
4. Hypertext,hypermedia and expertext.
5. Al and expert systems.
6. Neural networks and parallel programming.
7. Dicision support and office automation systems.
8. CIM / CAM / CAD system.
9.
4, STRUCTURE OF C++ PROGRAM
Include files
Class declaration
Class functions, definition
Main function
program
Example :-
# include<iostream.h>
class person
{
char name[30];
int age;
public:
void getdata(void);
void display(void);
};
void person :: getdata ( void )
{
cout<<”enter name”;
cin>>name;
cout<<”enter age”;
cin>>age;
}
void display()
{
cout<<”\n name:”<<name; cout<<”\
n age:”<<age;
}
int main( )
{
person p;
p.getdata();
p.display();
return(0);
}
5. Difference between Bottom-Up Model and Top-Down Model
Bottom-Up Design Model:
In this design, individual parts of the system are specified in detail. The parts are linked to
form larger components, which are in turn linked until a complete system is formed. Object-
oriented language such as C++ or java uses a bottom-up approach where each object is
identified first.
Advantage:
Make decisions about reusable low-level utilities then decide how there will be put
together to create high-level construct. ,
The contrast between Top-down design and bottom-up design.
Top-Down Design Model:
In the top-down model, an overview of the system is formulated without going into detail for
any part of it. Each part of it then refined into more details, defining it in yet more details
until the entire specification is detailed enough to validate the model. if we glance at a haul as
a full, it’s going to appear not possible as a result of it’s so complicated For example: Writing
a University system program, writing a word processor. Complicated issues may be resolved
victimization high down style, conjointly referred to as Stepwise refinement where,
1. We break the problem into parts,
2. Then break the parts into parts soon and now each of parts will be easy to do.
Advantages:
Breaking problems into parts help us to identify what needs to be done.
At each step of refinement, new parts will become less complex and therefore easier to
solve.
Parts of the solution may turn out to be reusable.
Breaking problems into parts allows more than one person to solve the problem.
TOP DOWN APPROACH BOTTOM UP APPROACH
In this approach We focus on In bottom up approach, we solve smaller
breaking up the problem into smaller problems and integrate it as whole and
1. parts. complete the solution.
Mainly used by structured Mainly used by object oriented
programming language such as programming language such as C++, C#,
2. COBOL, Fortran, C, etc. Python.
Each part is programmed separately Redundancy is minimized by using data
3. therefore contain redundancy. encapsulation and data hiding.
TOP DOWN APPROACH BOTTOM UP APPROACH
In this the communications is less
4. among modules. In this module must have communication.
It is used in debugging, module
5. documentation, etc. It is basically used in testing.
In top down approach, decomposition In bottom up approach composition takes
6. takes place. place.
In this top function of system might In this sometimes we can not build a
7. be hard to identify. program from the piece we have started.
In this implementation details may
8. differ. This is not natural for people to assemble.