17
AN OVERVIEW OF OBJECT ORIENTED PROGRAMMING By AKASH KHAITAN 08DDCS547 ICFAI Institute Of Science and Technology Dehradun

Object Oriented Programming

Embed Size (px)

DESCRIPTION

A report on Object Oriented Programming was prepared by me in order to fulfill the requirements of the Course Technical Report Writing

Citation preview

Page 1: Object Oriented Programming

AN OVERVIEW

OF

OBJECT ORIENTED PROGRAMMING

By

AKASH KHAITAN

08DDCS547

ICFAI Institute Of Science and Technology

Dehradun

Page 2: Object Oriented Programming

A REPORT

ON

OBJECT ORIENTED PROGRAMMING

EFFECT

By

AKASH KHAITAN

(08DDCS547)

Approved by :

Dr. T.Thapliyal

Instructor-In-Charge

Evaluated by :

Dr. T.Thapliyal

Instructor-In-Charge

A report submitted in partial fulfillment of course requirement

TA 204 Technical Report Writing

ICFAI Institute of science and Technology

Dehradun

06 APRIL, 2010

Page 3: Object Oriented Programming

ACKNOWLEDGEMENT

I would like to express my gratitude to Prof. R.C.Ramola Center Head ICFAI

TECH for allowing me to take up this course on TECHNICAL REPORT

WRITING.

I would also like to thank Dr.T.Thapliyal, Instructor In Charge of Technical

Report Writing, for giving useful knowledge and clarifying on writing good

reports and above all for giving me this opportunity to present my work with

this report.

I would like to thank my colleagues who have helped me in gathering the data

for this report.

iii

Page 4: Object Oriented Programming

Table of Contents

Acknowledgement iii

Abstract v

1 Introduction 1

2 Classes and Objects 2

3 Abstraction 3

4 Encapsulation 4

4.1 Advantages of Encapsulation 4

5 polymorphism 5

6 Inheritance 6

6.1 Benefits of inheritance in OOP 6

6.2 Types of inheritance 7

6.2.1 Single class inheritance 7

6.2.2 Multilevel inheritance 7

6.2.3 Multiple inheritance 7

6.2.4 Hierarchical Inheritance 8

6.2.5 Hybrid Inheritance 8

7 Benefits of OOP 9

8 Application of OOP 10

9 Conclusions 11

10 Bibliography xii

Page 5: Object Oriented Programming

ABSTRACT

This report provides an overview on a recent programming concept

“OBJECT ORIENTED PROGRAMMING”, which helps in writing

program more efficiently. It provides flexibility for the programmer,

helps in the reusability of a particular code. Most importantly it provides

a important feature for the programmer to hide the contents unnecessary

for the user. Almost all the new programming languages provide

functionality for this OOP concept

V

Page 6: Object Oriented Programming

1

1. Introduction Object oriented programming is a new way of organizing and developing programs and

has nothing to do with any particular language. Not all languages are suitable to

implement the OOP concept easily. Languages that support OOP features include C++,

Object Pascal, Ada, Java .The major objective of object – oriented approach is to

eliminate some of the flaws encountered in the procedural approach. Object oriented

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 unintentional modifications by other functions. Object oriented

programming allows us to decompose a problem into a number of entities called objects

and then build data and functions. The combination of data and methods make up an

object.

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

However, methods of one object can access the methods of other objects.

Some of the features of object-oriented paradigm are:

• Emphasis is on data rather than procedure

• Program are divided into what are known as objects

• Data structures are designated such that they characterize the objects

• Methods 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 networks

• New data and methods can easily added whenever necessary

• Follows bottom-up approach in program design

Object –oriented programming is 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.

Page 7: Object Oriented Programming

2

2. Classes and Objects This is one of the most important concept and requirement in the object oriented

programming .Classes are the basic building unit in the object oriented programming

concept that is all the required functions of a particular class type are defined in the class,

which can be accessed later according to the programmers need. The classes provide

flexibility for the programmers. Different classes can be made and can be used

accordingly using the concept of objects in different programs.

A object is instance of class that contains all the properties of class. To access a particular

member function/method of a particular class, dot operator is used.

A class may be thought as a data type and an object as a variable of that data type. Once a

class is defined, we can create any number of objects belonging to same class.

The object oriented programming has some of the following characteristics related to

objects:

• Everything is an object .An object stores data. One can “make requests” to that

object as well as asking it to perform operations on itself

• A program is a bunch of objects telling each other what to do by sending

messages.

• Each object has its own memory made up of other objects. Existing objects can be

composed together to create new objects. Small objects clubbed together to make

a bigger objects.

• Every object has a type. Similar objects are runtime instances of conceptual

pattern or type called class.

• All objects of a particular type can receive the same messages. This means the

objects of a particular class, which may be specialized from another class, respond

to same messages to behave similarly. This will lead to polymorphism to send

same interface to couple of objects belonging to a family of classes so that proper

method is called in appropriate class

Page 8: Object Oriented Programming

3

3. Abstraction The concept of abstraction relates to the idea of hiding data that are not needed for

presentation. The main idea behind data abstraction is to give a clear separation between

properties of data type and the associated implementation details. This separation is

achieved in order that the properties of the abstract data type are visible to the user

interface and the implementation details are hidden. Thus, abstraction forms the basic

platform for the creation of user-defined data types called objects. Data abstraction is the

process of refining data to its essential form. An Abstract Data Type is defined as a data

type that is defined in terms of the operations that it supports and not in terms of its

structure or implementation.

3.1 Reasons for the need of Abstraction

3.1.1 Flexibility in approach:

By hiding data or abstracting details that are not needed for presentation, the programmer

achieves greater flexibility in approach.

3.1.2 Enhanced Security:

Abstraction gives access to data or details that are needed by users and hide the

implementation details, giving enhanced security to application.

3.1.3Easier Replacement:

With the concept of abstraction in object-oriented programming language, it is possible to

replace code without recompilation. This makes the process easier and saves time for

users.

3.1.4 Modular Approach:

The abstraction concept helps users to divide the project application into modules and test

each of them separately. Then all modules are integrated and ultimately tested together.

This approach makes the application development easier.

Page 9: Object Oriented Programming

4

4. Encapsulation

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

encapsulation. Data encapsulation is the most striking feature of a class. The data is not

accessible to the outside world and only those methods which are wrapped in the class

can assess it. The methods provide the interface between the object’s data and the

program. This insulation of data from direct access by the program is called data hiding.

Encapsulation makes it possible for objects to be treated like ‘black boxes’ each

performing a specific task without any concern for the internal implementations. An open

example of this concept is in bank account, orkut etc

4.1 Advantages of Encapsulation

4.1.1 Modularity

If data is encapsulated within objects and objects can be manipulated only by a few

public interfaces available, then, keeping the same interface, if one changes the

implementation of a class of objects, then the users or clients of the objects remain

unaffected. As such, the clients programs don’t need to be changed because of change in

implementation of the objects they use. This helps to create modular programs

4.1.2 Information hiding

Objects communicate with other objects through available public interfaces. The object

can maintain private information and methods that can be changed at any time without

affecting the other objects they used. This helps to create modular programs

Information hiding is the principle of segregation of design decisions in a computer

program that are most likely to change, thus protecting other parts of the program from

extensive modification if the design decision is changed. The term encapsulation is often

used interchangeably with information hiding. In OOP, information hiding reduces

software development risk by shifting the code's dependency on an uncertain

implementation onto a well-defined interface. Clients of the interface perform operations

purely through it so if the implementation changes, the clients do not have to change.

Page 10: Object Oriented Programming

5

5. Polymorphism

Polymorphism is another important object oriented programming concept. Polymorphism

means the ability to take more than one form. It is type of a function overloading .For

example; an operation may exhibit different behavior in different instances. The

behaviors depend upon the types of data used in the operation.

Polymorphism plays an important role in allowing objects having different internal

structures to share the same external interface. This means that a general class of

operations may be accessed in same manner even though specific actions associated with

each operation may differ. Polymorphism is extensively used in implementing

inheritance.

Polymorphism is a programming language feature that allows values of different data

types to be handled using a uniform interface. The concept of parametric polymorphism

applies to both data types and functions. A function that can evaluate to or be applied to

values of different types is known as a polymorphic function.

It provides a facility that a same function can be called for different purpose depending

on the number and type of arguments.

Ex-Two differ shapes will be drawn under a common function but different parameters

Rectangle Circle

draw(x,y); draw(x);

Page 11: Object Oriented Programming

6

6. Inheritance

Inheritance is the concept of a child class (sub class) automatically inheriting the

variables and methods defined in its parent class (super class).A primary feature of

object-oriented programming along with encapsulation and polymorphism.

In object-oriented programming (OOP), inheritance is a way to form new classes

(instances of which are called objects) using classes that have already been defined.

Inheritance is employed to help reuse existing code with little or no modification. The

new classes, known as Sub-classes (or derived classes), inherit attributes and behavior of

the pre-existing classes, which are referred to as Super-classes (or ancestor classes). The

inheritance relationship of sub- and super classes gives rise to a hierarchy. The

inheritance concept was invented in 1967 for Simula.

Inheritance should not be confused with (subtype) polymorphism, commonly called just

polymorphism in object-oriented programming. Inheritance is a relationship between

implementations, whereas subtype polymorphism is relationship between types

(interfaces in OOP). (Compare connotation/denotation.) In some, but not all OOP

languages, the notions coincide because the only way to declare a subtype is to define a

new class that inherits the implementation of another. Inheritance does not entail

behavioral sub typing either. It is entirely possible to derive a class whose object will

behave incorrectly when used in a context where the parent class is expected

6.1 Benefits of Inheritance in OOP

Reusability: Once a behavior (method) is defined in a super class , that is the behavior

is automatically inherited by all subclasses. Thus a method is written only once and it can

be used by all subclasses. Once a set of properties (fields) are defined in a super class, the

same set of properties are inherited by all subclasses. A class and its children share

common set of properties. A subclass only needs to implement the differences between

itself and the parent.

Page 12: Object Oriented Programming

7

Overriding: Many object-oriented programming languages permit a class or object to

replace the implementation of an aspect—typically a behavior—that it has inherited. This

process is usually called overriding.

6.2 Types of Inheritance

6.2.1 Single class inheritance

When class a gas inherited in class has known as base class and B class is know as

derived class. Here only two classes have linked to each other.

6.2.2 Multilevel inheritance:

In this type of inheritance, there are number of level and it has used in that cases where

we want to use all properties in number of levels according to the requirement. For

example, class A inherited in class b and class b has inherited in class c for class b so on.

Where class A is base class c. In another way we can say b is derived class a base class

for c and a indirect base class for c is indirect base class for c and c indirect derived class

for class A.

6.2.3 Multiple Inheritance:

In this type of inheritance, number of classes has inherited in a single class. Where two or

more classes are, know as base class and one is derive class.

Page 13: Object Oriented Programming

8

6.2.4 Hierarchical Inheritance:

This type of inheritance helps us to create a baseless for number of classes and those

numbers of classes can have further their branches of number of class.

6.2.5 Hybrid Inheritance:

In this type of inheritance, we can have mixture of number of inheritances but this can

generate an error of using same name function from no of classes, which will bother the

compiler to how to use the functions. Therefore, it will generate errors in the program.

This has known as ambiguity or duplicity.

Page 14: Object Oriented Programming

9

7. Benefits Of OOP

Object oriented programming offers several benefits to both the program designer and

the user .Object oriented programming contributes to the solution of many problems

associated with the development and the quality of software products. The new

technology promises greater programmer productivity, better quality of software and

lesser maintenance cost.

The principal advantages of Object oriented programming are :

• Through inheritance we can eliminate redundant code and extend the use of

existing classes.

• We can build programs from the standard working modules that communicate

with the one another, rather then having to start writing the code from scratch.

This leads to saving of development time and higher productivity

• The principle of 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 multiple objects to coexist without any interference.

• It is possible to map objects in the problem domain to those objects in the

program

• It is easy to partition the work in the projects based on objects.

• Software complexity can be easily managed

While it is possible to incorporate all these features in Object oriented programming

system, their importance depends on the type of the project and the preference of the

programmer. There are a number of issues that need to be tackled to reap some of the

benefits stated above. The technology is still developing and current products may be

superseded quickly. Strict controls and protocols need to developed if reuse is not to

be compromised.

Page 15: Object Oriented Programming

10

8. Application of OOP

Object oriented programming is one the programming buzzwords today. There appears to

be great deal of excitement and interest among software engineers in using Object

oriented programming concept. Applications of Object oriented programming are

beginning to gain importance in many areas. The most popular application of Object

oriented programming, up to now has been in the area of user interface design such as

windows. There are many windowing systems developed using Object oriented

programming techniques.

Real-business systems are often much more complex and contain many more objects with

complicated attributes and methods. Object oriented programming is useful in this type of

applications because it can simplify a complex problem.

The promising areas for application of object oriented programming includes :

• Real-time systems

• Stimulation and modeling

• Object-oriented databases

• Hypertext, hypermedia and expertext

• AI and expert systems

• Neutral networks and parallel programming

• Decision support and office automation systems

• CIM/CAD/CAD system

It is believed that the richness of the Object-oriented programming environment will

enable the software industry to improve not only the quality of software systems but also

its productivity.

Page 16: Object Oriented Programming

11

9. Conclusion This report on Object oriented programming has let me conclude that Object oriented is

one of the most important concept in the programming which helps the programmer to

program more effectively and efficiently. The main feature is the flexibility of classes and

objects which saves programmer’s time. It provides some of the features like data

abstraction, encapsulation, polymorphism, inheritance which has made it possible for the

object oriented programming concept to be used in the real world situations.

So to be an effective programmer one must go through the concept of Object oriented

programming thoroughly.

Page 17: Object Oriented Programming

Bibliography 1. www.wikipedia.org

2. www.google.com

3. "Programming with JAVA" E Balagurusamy. Edition 2. 1998, p. 4

4. ”JAVA and Object-Oriented Programming Paradigm” Debasish Jana 2008 p. 32

Xii