0% found this document useful (0 votes)
72 views5 pages

Object Oriented Programming (Using Java)

Object-oriented programming (OOP) is an approach that models systems using objects that contain data and methods. It aims to reduce complexity and failure rates compared to conventional programming. OOP treats data as a critical element and ties it closely to the functions that operate on it. Key concepts include objects, classes, encapsulation, inheritance, polymorphism, and dynamic binding. Classes define common properties and behaviors of objects, while objects are instances of classes. Encapsulation binds data and methods together, hiding implementation details. Inheritance allows classes to inherit and add to features of other classes.

Uploaded by

Temesgen Tolcha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
72 views5 pages

Object Oriented Programming (Using Java)

Object-oriented programming (OOP) is an approach that models systems using objects that contain data and methods. It aims to reduce complexity and failure rates compared to conventional programming. OOP treats data as a critical element and ties it closely to the functions that operate on it. Key concepts include objects, classes, encapsulation, inheritance, polymorphism, and dynamic binding. Classes define common properties and behaviors of objects, while objects are instances of classes. Encapsulation binds data and methods together, hiding implementation details. Inheritance allows classes to inherit and add to features of other classes.

Uploaded by

Temesgen Tolcha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 5

Object Oriented Programming (using Java)

Chapter 1
1. Introduction

With the advent of languages such as C, structured programming became very popular and was
the paradigm of the 1980s. Structured programming proved to be a powerful tool that enabled
programmers to write moderately complex programs fairly easily. However, as the program grew
larger, even the structured approach failed to show the desired results in terms of bug –free, easy-
to-maintain and reusable programs.
Object-Oriented Programming (OOP) is an approach to program organization and development,
which attempts to eliminate some of the pitfalls of conventional programming methods by
incorporating the best of structured programming features with several new concepts. It is a new
of organizing and developing programs and has nothing to do with any particular. However, not
all languages are suitable to implement the OOP concepts easily. Languages that support OOP
features include Smalltalk, Objective C, C++, Ada and Object Pascal. C++, an extension of C
language, is the most popular OOP today. C++ is basically a procedural language with object-
oriented extension. The last one added to this list is Java, which is a pure object-oriented
language.

1.1. The Object Oriented Paradigm

What is Object Oriented P?


o Basically, it is a technique of modeling some kind of system in software based
Objects.
o It represents a fundamentally different way of thinking about a problem solving than
other software development methodologies.
o It enables us to reduce the software systems complexity and/or failure.
A research made by Standish Group in 1985 says,
 On average only 16.2% of projects are completed on time and with budget.
 31.1% of the projects were cancelled before they ever get completed.
 52.7% of the projects will cost 189% of their original estimate.
o 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 unintentional modification by other functions.
o OOP allows us to decompose a problem into a number of entities called Objects and
then build data and functions (known as Methods in java) around these entities.
The combination of data and methods make up an object (see Fig 1.1)

Method Method

Dat
a

1
Method + Methods
Fig 1.1 Object=data Method

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.

1.2 Features of Object Oriented paradigm

Programs are divided into what are known as objects.


Methods that operate on the data of an object are tied together in the data
structure.
Data is hidden and can not be accessed by external functions.
Emphasis is on data rather than procedures.
Objects may communicate with each other through methods.
Data structures are designed such that they characterize the objects.
New data and methods can be added whenever necessary.
Follows bottom-up approach in program design.

Definition:
OOP: - is an approach that provides a way of modularizing programs by creating partitioned
memory area for both data and methods that can be used as templates for creating copies of such
modules on demand. This means that an object is considered to be a partitioned area of computer
memory that stores data and a set of operations that can that data. Since the memory partitions
are independent, the objects can be used in a variety of different programs without modification.

1.3 Basic Concepts of Object Oriented Programming

Object
An object is a core concept, and is a model or representation of real-world entity or logical
idea or concept. It may represent a person, a place, a bank account, a able of data or any item
that the program may handle. It may also represent user-defined data types such as vectors
and lists. As pointed out earlier, an object takes up space in the memory and has an
associated address like a structure in C.
When a program is executed, the objects interact by sending messages to one another. For
example lets say ‘customer’ and ‘account’ are two objects in banking program, then the
customer object may send a message to the account object requesting for the balance. Each
object contains data and code to manipulate the data. Objects can interact without having to
know the details of each other’s data or code. It is sufficient to know the type of message
accepted and the type of response returned by the objects.

Class
We just mentioned that objects contain data and code to manipulate that data. The entire
set of data and code of an object can be made a user-defined data type using 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, we can create any number of objects belonging to
that class. Each object is associated with the data of type class with which they are

2
created. A class is thus a collection of objects of similar type. For Example mango, apple
and orange are members of the class fruit.

Definition: A class is a template used to create multiple objects with similar features.

Person Object
Name
Data
BasicSalary
Salary ()
Methods
Tax()

Fig 1.2 Representation of an Object

Classes are user-defined data types and behave like the built-in data types of a programming
language. For example , the syntax used to create an object is no different than the syntax
used to create an integer object in C++. If Fruit has been defined as a class, then the
statement
Fruit mango;
will create an object mango belonging to the class fruit.

1.4 Object-oriented principles


Data Abstraction and Encapsulation
The wrapping up of data 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 access it. This insulation of the data from direct access by the program is called data
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 abstract attributes such as size, weight, and cost and methods that
operate on these attributes. They encapsulate all 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. Inheritance supports the concept of hierarchical classification. 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 an existing one. The new class will have the combined features of both
the classes. Thus the real appeal and power of the inheritance mechanism is that it allows
the programmer to reuse a class that is almost, but not exactly, what he wants, and to
tailor the class in such a way that it does not introduce any undesirable side effects into
the rest of the classes.

3
Polymorphism
Polymorphism means the ability to take more than one form. For example, an operation
may exhibit different behavior in different instances. The behavior depends on the type of
data used in the operation.

Shape

Draw ()

Circle object Box object Triangle object

Draw (circle) Draw (box) Draw (triangle)

Fig 1.3 polymorphism

Polymorphism plays an important role in allowing objects having different internal


structure to share the same external interface.

Dynamic Binding
It refers to the linking of a procedure call to the code to be executed in response to
the call. Dynamic binding means that the code associated with a give procedure call is not
known until the time of the call at run time. It is associated with polymorphism and
inheritance. A procedure call associated with a polymorphic reference depends on the
dynamic type of that reference.
Consider the procedure ‘draw’ in Fig 1.3 above. By inheritance, every object will
have this procedure. Its algorithm is, however, unique to each object and so the draw
procedure will be redefined in each class that defines the object. At run-time, the code
matching the object under current reference will be called.

Message Communication
An object-oriented program consists of a set of objects that communicate with each
other. The process of programming in object-oriented language, therefore, involves the
following three basic steps:
1. Creating classes that define objects and their behavior.
2. Creating objects from class definitions.
3. Establishing communication among objects.

Objects communicate with one another by sending and receiving information much
the same way as people pass messages to one another. A message for an object is a

4
request for execution of a procedure, and therefore will invoke a method (procedure)
in the receiving object that generates the desired result.

Note: - Objects have life-cycle. They can be created and destroyed. Communication with
an object is feasible as long as it is alive.

1.5 Benefits of Object Oriented Programming


The following are some of the advantages of OOP:
 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 one another, rather than 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
can not be invaded by code in other parts of the program.
 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.
 Object-oriented systems can be easily upgraded from small to large systems.
 Message passing techniques for communication between objects make the
interface descriptions with the external systems much simpler.
 Software complexity can be easily managed.

1.6 Applications of OOP


The promising areas for application of OOP include:
 Simulation and Modeling
 Object-oriented database
 Hypertext and hypermedia
 AI(Artificial Intelligence) and expert systems.
 Real-time systems
 Neural networks and parallel programming
 Decision support and office automation systems.

You might also like