Basic Object Oriented Concepts: Name: Vinod Pillai Email

Download as pdf or txt
Download as pdf or txt
You are on page 1of 36

Basic Object Oriented Concepts

Name: VINOD PILLAI


Email:

vinodthebest@gmail.com

Object Oriented Programming

Developments in software technology continue


to be dynamic.

This maid the software industry and software


engineers to continuously look for new
approaches
to
software
design
and
development.
Rapid advances appear to have created a
situation of crisis within the industry.

Object Oriented Programming

Major issues need to resolved:

How to represente real-life entites


How to ensure reusability and extensibility of
modules
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

How to manage time schedules

Object Oriented Programming

Studies and other reports on software


implementation suggest that software products
should be evaulated carefully for their quality
before they are delivered and implemented.

Software Evolution

To built todays complex software it is just not


enough to put together a squence of
programming
statements
and
sets
of
procedures and modules; we need to
incorporate sound construction techniques and
program structures that are easy to
comprehend, implement and modify.
Since the invention of the computer, many
programming approaches have been tried.

Software Evolution

Such as Modular programming, top-down


programming, bottom-up programming and
structured programming.

The primary motivation in each case has been


the concern to handle the increasing complexity
of programs that are reliable and maintainable.

C vs C++

C Structured programming became very


popular and was the main technique of the
1980.

Structured programming enable programmers


to write moderately complex programs fairly
easily.
However as the programs grew larger, even the
structured approach failed to show the desired
results in terms of bug-free, easy-to-maintain
and reusable programs.

C vs C++

C++ - Object-Oriented Programming (OOP) is


an appraoch to program organization and
development that attempts to elimate some of
the pitfalls of conventional programming
methods by incorporating the best of structured
programming features with several powerful
new concepts.

Procedure-Oriented Programming

Conventional programming using high level


language such as COBOL, FORTRAN and C is
commonly known as Procedure-oriented
programming.

In the Procedure-oriented approach the


problem is viewed as a sequence of things to
be done such as reading, calculating and
printing.
The primary focus is on functions.

Structure of Procedure-oriented

Main Program

Function 1

Function 4

Function 2

Function 3

Function 5

Procedure-Oriented Programming

Procudure-oriented
programming
basically
consists of writing a list of instructions for the
computer to follow and organizing these
instructions into groups known as functions.

We normally use a flowchart to organize these


actions and represent the flow of control from
one action to another.
More importance to functions very little attention
to data that are being used by the functions.

Structure of Procedure-oriented

Global data

Function 1
Local data

Global data

Function 2

Function 3

Local data

Local data

Procedure-Oriented Programming

What happens to data? How are they affected


by the functions that work on them?

In multi-function program many important data


items are placed as global so that they may be
accessed by all the functions.Each function may
have its own local data.
In large program it is very difficult to identify
what data is used by which function. In case we
need to revise an external data structure we
also need to revise all function that access it.

Object-Oriented Programming

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 entites called objects.

Organization of data & function OOP


Object A

Object B

Object A

Object B

Data

Data

Functions

Functions

Object C
Data

Functions

Striking features of OOP

Emphasis is on data rather than procedure.

Programs are divided into what are known as objects

Functions that operate on the data of an object are


tied together in the data structure
Data is hidden and cannot be accessed by external
functions
Objects may communicate with each other through
functions

New data and functions can be easily added whenever


necessary.

Object-oriented programming

Object-oriented programming is an approach that


provides a way of modularizing programs by creating
partitioned memory area of both data and fucntions
that can be used as templates for creating copies of
such modules on demand.
Object is considered to be a partitoned area of
computer memory that stores data and set of
operations that can access that data.

Basic concepts of OOP

Objects

Class

Data Abstration

Data Encapsulation

Inheritance

Polyomorphism

Dynamic binding

Message Passing

The three pillars of object-oriented development:

Encapsulation, Inheritance, and Polymorphism.

Objects

Objects are the basic run-time entities in an objectoriented system.


They may represent a person, a place, a bank
account, a table of data or any item that the program
must handle.
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 sturcture in C.

When a program is executed the objects interact by


sending messages to one another.

Objects

Ways to represent an Object

Object: STUDENT

DATA
Name
Marks
FUNCTIONS
Total
Display

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.
Objects are variable of type class.

Once a class has been defined we can create any


number of objects belonging to that class.
A class is thus a collection of objects of similar type.
Classes are user-defined data types and behave like
the built-in types of a programming language.

Classes

Syntax used to create an object is no different than the


syntax used to create an integer object in C.

Fruit is a class defined as a Class.

fruit f1;

Here fruit is Class.

And f1 is an object of fruit Class.

Encapsulation

The wrapping up of data and functions into a single


unit 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.
This insulation of the data from direct access by the
program is called data hiding or information

hiding.

Data Abstraction

Abstraction refers 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
functions.

Since the classes use the concept of data


abstraction, they are known as Abstract Data
Types.

Inheritance

Inheritance is the process by which objects of one


class acquire the properties of objects of another
class.
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.

Inheritance

The real power of 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.
Bird

Flying Bird

No flying Bird

Polymorphism

Polymorphism means the ability to take more than one


form.
That is an operation may exhibit different behaviours
in different instances. The behaviour depends upon
the types of data used in the operation.
Example: Operation of addition.
For two numbers the operation will generate a sum. If
the operands are strings, then the operation would
produce a third string by concatenation.

Polymorphism

The process of making an operator to exhibit different


behaviours in different instances is known as

operator overloading.

Using a single function name to perform different types


of taks is known as function overloading.

Dynamic Binding

Binding refers to the linking of a porcedure call to the


code to be executed in response to the call.
Dynamic binding means that the code associated with
a given procedure call is not known until the time of
the call at run-time

It is associated
inheritance.

with

polymorphism

and

Message Communication

An object-orineted program consits of a set of objects


that communicate with each other.

Object communicate with one another by sending and


receiving information much the same way as people
pass message to one another.
Message passing involves specifying the name of the
object, the name of the funciton (message) and the
information to be sent.
emp.salary(emp_name);
object

message

information

Benefits of OOP

Through inheritance we can elimate the redundant


code and extend the use of existing code
Data hiding helps the programmer to build secure
programs that cannot be invaded by code in other
parts of the program
It is possible to have mulitple instances of an objects
to co-exist without any interference.
It is possible to map objects in the problem domain to
those objects in the program

Easy to partition the work in a project based on objects

Benefits of OOP

Data-centred design approach enables us to capture


more details of a model in implementable form
Object-oriented systems can be easily upgraded from
small to large systems
Software complexity can be easily managed.

Object-Oriented Languages

The lanugages should support several of the OOP


concepts to claim that they are object-oriented.
Depending upon the features they support, they can
be classified into the following two categories:

Object-based programming lanugages

Object-oriented programming languages

Object-based programming Languages

Object-based programming is the style of


programming that primarily supports encapsulation
and object identify.
Major features:

Data encapsulation

Data hidding and access mechanisms

Automatic initialization and clear-up objects

Operator overloading

They do not support inheritance and dynamic


binding.

Object-oriented programming Languages

Object-oriented programming incorporates all of


object-based programming features along with two
additional features, namely, iheritance and dynamic
binding.
Object-based features + inheritance + dynamic binding

References

Object-Oriented
Balagurusamy

Programming

with

C++

by

You might also like