Tuesday, 7 August 2018

CONCEPTS OF OBJECT ORIENTED PROGRAMMING


CONCEPTS OF OBJECT ORIENTED PROGRAMMING

The various concepts of OOP are
# Objects
# Classes
# Data abstraction and encapsulation
# Inheritance
# Polymorphism
# Dynamic binding
# Message passing

Object: Objects are the basic run-time entities in an object-oriented system. They may
represent a person, a place, a bank account, a table of data or any item that the
program has td handle. Objects take up space in the memory and have an associated
address like a record in Pascal or a structure in c.

Classes: Classes are user-defined data types and behave like the built-in types of a
programming language. The entire set of data and code of an object can be made a
user-defined data type with the help of a class. In fact, objects are variables of the
type class. Each object is associated with the data of type class with which they are
created. A class is a collection of objects of similar type. For example mango, apple
and orange are members of the class fruit.

Fruit mango;
Will create an object mango belonging to the class fruit.

Data Abstraction and Encapsulation: The wrapping up of data and functions into a
single unit is known as encapsulation. Data abstraction is done using the classes. 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.

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 attributes and functions to operate on these attributes. They
encapsulate all the essential properties of the objects that are to be created.

Inheritance: Inheritance is the process by which objects of one class acquire the
properties of objects of another class. It supports the concept of hierarchical
classification. For example the bird robin is a part of the class flying bird which is again a
part of the class bird. The idea behind this sort of division is that each derived class shares
common characteristics with the class form which it is derived. Inheritance provides the idea
of reusability.

There are Five types of Inheritance
a) Single
b) Multiple
c) Multilevel
d) Hierarchical
e) Hybrid
Single inheritance: Derivation of a class from only one base class is called single
inheritance.

Multiple inheritance: Derivation of a class from two or more classes is called multiple
inheritances.

Hierarchical inheritance: Derivation of several classes from a single base class i.e. the traits
of one class may be inherited by more than one class is called hierarchical inheritance.

Multilevel inheritance: Derivation of a class from another derived class is called multilevel
inheritance.

Hybrid inheritance: Derivation of a class involving more than one form of inheritance is
known as hybrid inheritance.

Multipath inheritance: Derivation of a class from other derived classes, which are derived
from the same base class, is called multipath inheritance.


Polymorphism: Polymorphism, a Greek term, means the ability to take more than one form.
The following are the different ways of achieving Polymorphism in Java.

The process of making an operator to exhibit different behaviours in different instances is
known as operator overloading . For example consider the operation of addition For two
numbers the operation will generate a sum. If the operands were strings then the operation
would produce a third string by concatenation.
Using a single function name to perform different types of tasks is known as function
overloading.

Dynamic binding: Binding refers to the linking of a procedure call to the code to be
executed in response to the call. Dynamic binding also known as late 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 with polymorphism and inheritance .

Message Passing : An object –oriented program consists of a set of objects that
communicate with each other. A message for an object is a request for execution of
a procedure and therefore will invoke a function in the receiving object that generates
the desired result. It involves specifying the name of the object, the name of the
function and the information to be sent.
For example
Employee. Salary(name);
Employee is object, salary is message and name is information.

No comments: