Object Oriented Programming
Object Oriented Programming
By
AKASH KHAITAN
08DDCS547
By
AKASH KHAITAN
(08DDCS547)
A report submitted in partial fulfillment of course requirement TA 204 Technical Report Writing ICFAI Institute of science and Technology Dehradun 06 APRIL, 2010
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
Table of Contents
Acknowledgement Abstract iii v
1
2 3 4
Introduction
Classes and Objects
1
2 3 4 4 5 6 6 7 7 7 7 8 8 9 10 11 xii
Abstraction
Encapsulation 4.1 Advantages of Encapsulation
5 6
polymorphism Inheritance 6.1 Benefits of inheritance in OOP 6.2 Types of inheritance 6.2.1 Single class inheritance 6.2.2 Multilevel inheritance 6.2.3 Multiple inheritance 6.2.4 Hierarchical Inheritance 6.2.5 Hybrid Inheritance
7 8 9 10
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
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.
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
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.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.
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 objects 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
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 draw(x,y); Circle draw(x);
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. 6
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.
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.
10
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 programmers 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.
11
Bibliography
1. www.wikipedia.org 2. www.google.com 3. "Programming with JAVA" E Balagurusamy. Edition 2. 1998, p. 4
Xii