Download as pdf or txt
Download as pdf or txt
You are on page 1of 5

Faculty of Computing and Software Engineering

CHAPTER ONE

Basics of object oriented programming (OOP)


Software technology has evolved through a series of phases during the last 5 decades.
Programming approaches that have been tried since the invention of the computer includes
techniques such as modular programming, top-down programming, bottom-up programming and
structured programming. The primary motivation in the evolution has been to handle the
complexity of programs that are reliable and maintainable.

Object oriented programming (OOP) is an approach to program organization and development


that attempts to eliminate some of the pitfalls of conventional programming methods by
incorporating the best of structured programming features with several powerful new concepts.
Procedure Oriented Programming (POP) Vs Object Oriented Programming (OOP)
POP employs top-down programming approach. A program in a procedural language is a list of
instructions where each statement tells the computer to do something. The focus is on the
processing, the algorithm needed to perform the desired computation. So, the principle used here
is Decide which procedure you want; use the best algorithm you can find. Languages
support this paradigm by providing facilities for passing arguments to functions and returning
values from functions. Here the problem is viewed as a sequence of things to be done such as
reading, calculating and printing. And for this a number of functions are written. Very little
attention is given to the data & how are they are affected by the functions that work on them.

Summarize the characteristics of procedure-oriented programming:

 Emphasis is on doing things.


 Large problems are divided into smaller programs known as functions
 Most of the functions share global data.
 Data passes from function to function freely.
 Functions transform data from one form to another.
 Employs top-down approach in program design.

Compiled by Behayilu M. Page 1


Faculty of Computing and Software Engineering

POP has 2 major drawbacks.

1) Data moves freely around the program and therefore vulnerable to any changes caused
by any function in the program
2) It does not model very well the real-world problems.
OOP was invented to overcome the drawbacks of the POP. It employs bottom-up programming
approach. OOP 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 accidental modification from outside functions. OOP allows decomposition of a
problem into a number of entities called objects and then builds data and functions around them.
Object – Oriented approach views a problem in terms of objects involved rather than procedure
for doing it.

Summarize the characteristics of Object-Oriented programming:

 Emphasis is on data rather than procedure.


 Programs are divided into what are known as objects.
 Functions 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 functions
 New data and functions can be easily added whenever necessary.
 Employs bottom-up approach in program design.
Definition
OOP is an approach that provides a way of modularizing programs by creating partitioned
memory areas for both data and functions that can be used as templates for creating copies of
such modules on demand.

That is  Object is considered to be a partitioned area of computer memory. It stores data and
set of operations that can access that data. Since the memory partitions are independent, the
objects can be used in a variety of different programs without modifications.

Compiled by Behayilu M. Page 2


Faculty of Computing and Software Engineering

Some of the concepts used in Object oriented Programming


Objects : Object is an identifiable entity with some characteristics and behavior.

Real view  ‘Apple’ is said to an object. Its characteristics are shape--spherical,


colour—-red and so on. Its behavior is: it is juicy and its taste is sweet.
OOP view Characteristics of an object are represented by its data, and its behavior is
represented by its functions associated.
In procedural programming the traffic flow at red light crossing will be viewed in terms of
what’s happening in the traffic flow, i.e., moving, halting etc. But in OOP’s the problem will be
viewed in terms of objects involved. i.e.) is cars, trucks, buses and so on.
Class: A class is a group of objects that share common properties and relation-ships.
Real view  In OOP’s the traffic flow at red light crossing is viewed in terms of objects. And
here we treated car as an object. But it can be treated as a class. And ‘Opel
astra’ can be treated as an object. ‘Car is a subclass ‘Automobile’ which again is
a subclass of ‘Vehicles’.
OOP view Class is a collection of objects of similar type. We know objects contain
data and function code to manipulate that data. With the help of class the entire
set of data and code of an object can be made a user defined data type. Thus
objects are variables of type class. Once the data type, class has been created we
can create any number of objects belonging to that class.
Features of Object Oriented Programming
1. Data Abstraction
Abstraction refers to the act of representing essential features without including the
background details or explanations. For example consider the example of a ‘switch board’.
When we press a switch according to our requirement, we don’t know what is happening
inside. This is abstraction, i.e.) we know the essential thing to operate on switchboard
without knowing the background details.
Classes use the concept of abstraction and are defined as a list of abstract attributes and
functions to operate in these attributes. These attributes are known as data members and
functions are called methods or member functions.

Compiled by Behayilu M. Page 3


Faculty of Computing and Software Engineering

Since these classes, which are the user defined types use the concept of data abstraction
they are known as Abstract Data types.
2. Encapsulation
The wrapping up of data and functions (that operate upon the data) into a single unit (called
class) is known as encapsulation. This is a way to implement abstraction. We can access the
data only through the functions (known as member functions) that are combined along with
the data. They cannot be accessed directly.
Thus we can say that data is hidden and so it is safe from accidental alteration. Data and
functions are said to be encapsulated into a single entity. This insulation of the data from
direct access by the program is called data hiding or information hiding.
3. Inheritance
This is the capability of one class of things to inherit capabilities or properties from any
other class.
E.g.:
Vehicles

Automobiles Pulled Vehicles

Car Cart
Roles:
 Its capability to express the inheritance relationship, which makes it, ensure the
closeness with the real-world models.
 Another is the idea of reusability. Inheritance allows the addition of additional
features to an existing class without modifying it. This is possible by deriving a
new class from the existing class one. The new class will have the combined
features of both the classes.
 The third reason is its transitive nature. If a class A inherits properties of another
class B, then all subclasses of A will automatically inherit the properties of B.
4. Polymorphism
The term means the ‘ability to take more than one form’. Thus Polymorphism can be defined
as the ability for a message or data to be processed in more than one form.

Compiled by Behayilu M. Page 4


Faculty of Computing and Software Engineering

Consider the eg: Dog and Cat both are subclasses of Animal. Now the message ‘see through
daylight’ when passes to these classes will behave alike. But the message ‘see through night’
will behave differently since dogs will not be able to view at night whereas cats can.
Types of Java Applications

There are mainly 4 types of applications that can be created using java:

1) Standalone Application

It is also known as desktop application or window-based application. An application that we


need to install on every machine such as media player, antivirus etc. AWT and Swing are used
in java for creating standalone applications.

2) Web Application

An application that runs on the server side and creates dynamic page, is called web
application. Currently, servlet, jsp, struts, jsf etc. technologies are used for creating web
applications in java.

3) Enterprise Application

An application that is distributed in nature, such as banking applications etc. It has the
advantage of high level security, load balancing and clustering. In java, EJB is used for creating
enterprise applications.

4) Mobile Application

An application that is created for mobile devices. Currently Android and Java ME are used for
creating mobile applications.

Compiled by Behayilu M. Page 5

You might also like