This chapter briefly discusses different concepts that are
pertaining to an object oriented programming. However, all the related details
to these concepts are deferred to the later chapters.
Object Oriented
Programming
Object oriented programming, as its name suggests, relies on
the object for programming. As a matter of fact, every real entity, or
hypothetical entity, can be conceived as a bundle with its attributes (or
states) and behaviors. That’s what we call an object. It is true that we can
come up with the representation of entities as a combination of attributes and
behaviors and such bundles can interact among each other to perform well
defined task. This is the real principle behind the OOP. Here students must
take care on the distinguishing remark of the OOP that it focuses on data
portion rather than the process of solving the problem (algorithm). The
emphasized data are manipulated using suitable interface called functions or
methods in Java.
Abstraction
Abstraction is the essence of OOP. Abstraction means the
representation of the essential features without providing the internal details
and complexities. In OOP abstraction is achieved by the help of class
(described later), where data and methods are combined to extract the essential
features only. For example, if we represent chair as an object it is sufficient
for us to understand that the purpose of chair is to sit. So we can hide the
details of construction of chair and things required to build the chair.
OOP
Principles
Each description of OOP is incomplete without the
presentation of the concepts encapsulation, inheritance, and polymorphism. Here
are the brief descriptions for each.
-Encapsulation
Encapsulation is the process of combining the data (called
fields or attributes) and methods (called functions or behaviors) into a single
framework called class. Encapsulation helps preventing the modification of data
from outside the class by properly assigning the access privilege to the data
inside the class. So the term data
hiding is possible due to the concept of encapsulation, since the data are
hidden from the outside world.
-Inheritance
This is the thrilling concept in OOP. Inheritance is the
process of acquiring certain attributes and behaviors from the parents, and so
is it in case of OOP. If we derive some class from the class (called super
class), then some of the properties and methods can be inherited so that we can
reuse the already written and tested code in our program, simplifying our
program. (More on this later)
-Polymorphism
The representation of different behaviors using the same name
is called polymorphism. However the behavior depends upon the attribute the
name holds at particular moment. For example if we have the method called
communicate for the objects vertebrates, then the communicate method applied to
objects say dogs is quite different from the communicate method applied to
objects human (can you think how?). So here the same name communicate is used
in multiple process one for human communication, what we simply call talking.
The other is used fro communication among dogs, we may say barking, definitely
not talking. (More on polymorphism later)
Classes and
Objects
The concept of classes and objects is the crux of the OOP. In
this part of the lecture we simply discuss what are class and objects. In the
later chapters we will discuss about them in greater detail. Class is a
framework that combines the attributes and the behavior of the set of similar
objects and object is the realization of the class that the object belongs to.
For example we can think of the class Students.
This class has some properties like name, address, grade, and so on. Similarly
it can have the methods like isBbisIIYear(), IsLAStudent(), etc. Now here we
can see that the class Student refers to the group of all students however the
realization of the class say “MrX” (some student) answers all the unfilled
attributes and the truth value of the methods given. This realization of class
as particular entity is called an object of the class. In programming we say
that an object is an instance of the class. More
on this in chapters to follow.
Message
When we think everything as an object, it is not sufficient
for doing all the complex task just by representation of the objects. For
example let’s take objects mydog of
the class, say Dogs, and davidprasad
of the class, say Human. If we have the relation between the object mydog and
davidprasad as davidprasad tames mydog, then there should be the way of relating
two objects of different kind. This kind of relation is provided with the help
of communication between two objects and this communication is done through
information called message.
Interface
Interface is the method that provides us the facility of
manipulating the object. For example in our computer, if we want to close the
window we click on window close button on the top right corner. Here the button
for window close is an interface (method) for closing the window (state of an
object is changing here). In java, the collection of methods without definition
is bundled so as to use with similar objects. This collection of methods is
called an interface. More on this later.
Benefits of
OOP
Some of the benefits are:
·
Modularize the programs. Modular programs are
easy to develop and can be distributed independently among different
programmers.
·
Data hiding is achieved with the help of
encapsulation
·
Data centered approach rather than process
centered approach.
·
Program complexity is low due to distinction of
individual objects and their related fields and behaviors.
0 comments:
Post a Comment