Chapter 1
Chapter 1
Unit-1
Chapter 1
Fundaments of Object-Oriented Programming
2 Marks:
given procedure call is not known until the time of the call at runtime. It is
associated with polymorphism and inheritance
6. Dynamic Binding
7. Message Communication
Object and Classes
Objects are the basic runtime entities. It represents a person, a place, a bank
account, a table of data or any item. They may also represent user-defined data
types. When a program is executed, the objects interact by sending messages to
one another. For example, ‘customer’ and ‘account’ are 2 objects in a banking
program, then the customer object may send a message to the account object
requesting for the balance. Each object contains data and code. The below
figure shows a notation that is popularly used to represent an object in object-
oriented analysis and design
Object
Person
Name Data
BasicPay
Salary() Methods
Tax()
The entire set of data and code of an object can be made a user-defined data
type using the concept of a class. A class may be thought of as a ‘data type’ and
an object as a ‘variable’ of that data type. Once a class has been defined, awe
can create any number of objects belonging to that class. Each object is
associated with the data of type class with which they are created. A class is
thus a collection of objects of similar type. For example, mango, apple, and
orange are members of the class fruit
Data Abstraction and Encapsulation
The wrapping up of data and methods into a single unit (called class) is known
as encapsulation. The data is not accessible to the outside world and only those
methods, which are wrapped in the class, can access it. These methods provide
the interface between the object’s data and the program. This insulation of the
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 internal implementation (see below figure)
Inheritance
Inheritance is the process by which objects of one class acquire the properties of
another class. Inheritance supports the concept of hierarchical classification. For
Abstraction refers to the act of representing essential features without including
the background details or explanations. Example, mobile phones
example, the bird robin is a part of the class flying bird, which is again a part of
the class bird. It is illustrated in below figure.
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.
This is possible by deriving a new class from the existing one. The new class
will have the combined features of both the classes
Polymorphism
Polymorphism is another important OOP concept. Polymorphism means the
ability to take more than one form. For example, consider the operation of
addition. For 2 numbers, the operation will generate a sum. If the operands are
strings, then the operation would produce a third string by concatenation. The
below figure illustrates that a single function name can be used to handle
different number and different types of arguments
Message
Method()
OOP offers several benefits to both the program designer and the user.
principal advantages are:
• Through inheritance, we can eliminate redundant code and extend the use
of existing classes.
• It saves development time and gives higher productivity.
• Data hiding helps the programmer to build secure programs.
• It is possible to have multiple objects to coexist without any interference.
• It is easy to partition the work in a project based on objects.
• Easily upgraded from small to large systems.
• Message passing techniques for communication between objects make
the interface descriptions with external systems much simpler.
• Software complexity can be easily managed