object oriented programming system · 2/3/2017 · procedure oriented programming object oriented...

24
Object Oriented Programming System OOC 4 th Sem, ‘B’ Div 2016-17 Prof. Mouna M. Naravani

Upload: buihuong

Post on 24-Jun-2018

259 views

Category:

Documents


6 download

TRANSCRIPT

Page 1: Object Oriented Programming System · 2/3/2017 · Procedure Oriented Programming Object Oriented Programming In POP, ... Sourav Sahay, “Objected Oriented Programming with C++”

Object Oriented Programming System

OOC

4th Sem, ‘B’ Div

2016-17

Prof. Mouna M. Naravani

Page 2: Object Oriented Programming System · 2/3/2017 · Procedure Oriented Programming Object Oriented Programming In POP, ... Sourav Sahay, “Objected Oriented Programming with C++”

Object Oriented Programming (OOP) removes some of the flaws encountered in

POP.

In OOPs, the primary focus is on data rather than procedure.

The data cannot be moved freely around the system.

OOPs ties data more closely to the functions that operate on it, and protects it

from accidental modification from outside functions.

The functions cannot exist without data, and data need functions to give it a

shape.

Page 3: Object Oriented Programming System · 2/3/2017 · Procedure Oriented Programming Object Oriented Programming In POP, ... Sourav Sahay, “Objected Oriented Programming with C++”

Organization of data and functions in OOP

Page 4: Object Oriented Programming System · 2/3/2017 · Procedure Oriented Programming Object Oriented Programming In POP, ... Sourav Sahay, “Objected Oriented Programming with C++”

OOP allows decomposition of a problem into a number of entities called objects and

then builds data and functions around these objects.

Data is hidden and cannot be shared by outside functions.

The data of an object can be accessed only by the functions associated with that object.

The objects that are created may interact with each other via functions.

OOPs follows Bottom-up approach, because the objects are created first and the data

and functions around them are developed later.

Page 5: Object Oriented Programming System · 2/3/2017 · Procedure Oriented Programming Object Oriented Programming In POP, ... Sourav Sahay, “Objected Oriented Programming with C++”

Some of the striking features of object-oriented programming are:

Emphasis is on data rather than procedure.

Programs are divided into what are known as objects.

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.

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.

Follows bottom-up approach in program design.

Page 6: Object Oriented Programming System · 2/3/2017 · Procedure Oriented Programming Object Oriented Programming In POP, ... Sourav Sahay, “Objected Oriented Programming with C++”

OOP

Classes

ObjectsMessage

Passing

Polymorphism

Data Abstraction

and Encapsulation

Inheritance

BASIC CONCEPTS OF Object Oriented Programming

Page 7: Object Oriented Programming System · 2/3/2017 · Procedure Oriented Programming Object Oriented Programming In POP, ... Sourav Sahay, “Objected Oriented Programming with C++”

Objects:

Objects are basic run time entities in OOP.

It may represent a person, a bank account, a place, a table of data, vectors, etc.

Objects should be chosen such that they match closely with real-world objects.

Ex: Name, DOB, Address, Age, Mobile number. If these details are required for

student, create STUDENT object. If these details are required for customer, create

CUSTOMER object. If these details are required for employee, create EMPLOYEE object.

Objects occupy space in the memory and have an associated address.

When a program is executed, the objects interact by sending messages to one another.

Ex: If “CUSTOMER” and “ACCOUNT” are two objects, then the CUSTOMER

object may send a message to the ACCOUNT object requesting for bank balance.

Page 8: Object Oriented Programming System · 2/3/2017 · Procedure Oriented Programming Object Oriented Programming In POP, ... Sourav Sahay, “Objected Oriented Programming with C++”

Objects contain both data and operations that manipulate these 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

returned by the objects.

Page 9: Object Oriented Programming System · 2/3/2017 · Procedure Oriented Programming Object Oriented Programming In POP, ... Sourav Sahay, “Objected Oriented Programming with C++”

Classes:

A class is a collection of objects of similar type.

The entire set of data and code of an object can be made a user defined data type with

the help of a class.

Once a class is defined, any number of objects belonging to that class can be created.

Page 10: Object Oriented Programming System · 2/3/2017 · Procedure Oriented Programming Object Oriented Programming In POP, ... Sourav Sahay, “Objected Oriented Programming with C++”
Page 11: Object Oriented Programming System · 2/3/2017 · Procedure Oriented Programming Object Oriented Programming In POP, ... Sourav Sahay, “Objected Oriented Programming with C++”

Encapsulation:

The wrapping up of data and functions into a single unit (called class) is known as

Encapsulation.

It hides the implementation details of an object from its users.

Encapsulation prevents unauthorized access of data or functionality.

The data is not accessible to the outside world, and only functions which are wrapped

in the class can access it.

This is called data hiding or information hiding.

Page 12: Object Oriented Programming System · 2/3/2017 · Procedure Oriented Programming Object Oriented Programming In POP, ... Sourav Sahay, “Objected Oriented Programming with C++”

Data Abstraction:

Abstraction refers to the act of representing essential features without including

background details or explanations.

It separates unnecessary details or explanations so as to reduce complexities of

understanding requirements.

Page 13: Object Oriented Programming System · 2/3/2017 · Procedure Oriented Programming Object Oriented Programming In POP, ... Sourav Sahay, “Objected Oriented Programming with C++”

Inheritance:

Inheritance is the process by which objects of one class acquire the properties of objects

of another class.

Hierarchical Classification

Reusability – adding additional features to an existing class without modifying it.

That is, deriving a new class from the existing one.

The new class will have the combined features of both the classes.

New class is also called as Derived class and existing class is called as Base Class.

Page 14: Object Oriented Programming System · 2/3/2017 · Procedure Oriented Programming Object Oriented Programming In POP, ... Sourav Sahay, “Objected Oriented Programming with C++”
Page 15: Object Oriented Programming System · 2/3/2017 · Procedure Oriented Programming Object Oriented Programming In POP, ... Sourav Sahay, “Objected Oriented Programming with C++”

Polymorphism: (having many forms)

Ability to take more than one form.

The polymorphism is an ability to access different implementations of a function using

the same name.

Ex: Function to perform addition operation

Input Output

Two integer numbers integer sum

Two float numbers float sum

Two strings constants concatenation

Page 16: Object Oriented Programming System · 2/3/2017 · Procedure Oriented Programming Object Oriented Programming In POP, ... Sourav Sahay, “Objected Oriented Programming with C++”

Addition Operation

add(int, int) add(float, float) add(string, string)

Page 17: Object Oriented Programming System · 2/3/2017 · Procedure Oriented Programming Object Oriented Programming In POP, ... Sourav Sahay, “Objected Oriented Programming with C++”

Operator Overloading: The process of making an operator to exhibit different

behaviours in different instances.

Function Overloading: Using a single function name to perform different types of

tasks.

Page 18: Object Oriented Programming System · 2/3/2017 · Procedure Oriented Programming Object Oriented Programming In POP, ... Sourav Sahay, “Objected Oriented Programming with C++”

Dynamic Binding:

Dynamic binding (late binding) means that the code associated with a procedure

call is not known until the time of the call at run-time.

Usually associated with Polymorphism and Inheritance.

At run-time, the code matching the object under current reference will be called.

Page 19: Object Oriented Programming System · 2/3/2017 · Procedure Oriented Programming Object Oriented Programming In POP, ... Sourav Sahay, “Objected Oriented Programming with C++”

Message Passing:

Set of objects communicate with each other.

Steps involved:

1. Creating classes that define objects and their behaviour.

2. Creating objects from class definitions.

3. Establishing communication among objects.

Objects communicate with one another by sending and receiving information.

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 the information to be sent.

Page 20: Object Oriented Programming System · 2/3/2017 · Procedure Oriented Programming Object Oriented Programming In POP, ... Sourav Sahay, “Objected Oriented Programming with C++”

Objects have a life cycle. They can be created and destroyed.

Communication with an object is feasible as long as it is alive.

employee.salary(name);

Objectmessage

Information

Page 21: Object Oriented Programming System · 2/3/2017 · Procedure Oriented Programming Object Oriented Programming In POP, ... Sourav Sahay, “Objected Oriented Programming with C++”

Procedure Oriented Programming Object Oriented Programming

In POP, program is divided into small parts

called functions.

In OOP, program is divided into parts

called objects.

In POP, Importance is not given to data but to

functions as well as sequence of actions to be

done.

In OOP, Importance is given to the data rather

than procedures or functions because it works

as a real world.

POP follows Top Down approach. OOP follows Bottom Up approach.

POP does not have any access specifier. OOP has access specifiers named Public,

Private, Protected, etc.

In POP, Data can move freely from function to

function in the system.

In OOP, objects can move and communicate

with each other through member functions.

To add new data and function in POP is not so

easy.

OOP provides an easy way to add new data

and function.

Difference between Procedure Oriented Programming and Object Oriented Programming

Page 22: Object Oriented Programming System · 2/3/2017 · Procedure Oriented Programming Object Oriented Programming In POP, ... Sourav Sahay, “Objected Oriented Programming with C++”

Procedure Oriented Programming Object Oriented Programming

In POP, Most function uses Global data for

sharing that can be accessed freely from

function to function in the system.

In OOP, data can not move easily from

function to function, it can be kept public or

private so we can control the access of data.

POP does not have any proper way for hiding

data so it is less secure.

OOP provides Data Hiding so provides more

security.

In POP, Overloading is not possible. In OOP, overloading is possible in the form of

Function Overloading and Operator

Overloading.

Example of POP are : C, VB, FORTRAN,

Pascal.

Example of OOP are : C++, JAVA, VB.NET,

C#.NET.

Page 23: Object Oriented Programming System · 2/3/2017 · Procedure Oriented Programming Object Oriented Programming In POP, ... Sourav Sahay, “Objected Oriented Programming with C++”

References

Sourav Sahay, “Objected Oriented Programming with C++”

E Balagurusamy, “Objected Oriented Programming with C++”

P. B. Kotur, “Objected Oriented Programming with C++”

Page 24: Object Oriented Programming System · 2/3/2017 · Procedure Oriented Programming Object Oriented Programming In POP, ... Sourav Sahay, “Objected Oriented Programming with C++”