Concept of
programming
MUHAMMAD NASIR IQBAL
DEPARTMENT OF BIOINFORMATICS, IBBB,
IUB, PK
Software Crisis
The following issued need to be addressed
to face the crisis:
• How to represent real-life entities of
problems in system design?
• How to design system with open
interfaces?
• How to ensure reusability and extensibility
of modules?
• How to develop modules that are tolerant
of any changes in future?
• How to improve software productivity and
decrease software cost?
• How to improve the quality of software?
• How to manage time schedules?
Software
Evolution
In the procedure-oriented
approach, the problem is viewed as
the sequence of things to be done
Procedure- such as reading, calculating and
printing such as cobol, fortran and
Oriented
c. The primary focus is on functions.
Programming The technique of hierarchical
decomposition has been used to
specify the tasks to be completed
for solving a problem.
Procedure-Oriented Programming
Procedure-Oriented
Programming
• Procedure oriented programming basically consists of
writing a list of instructions for the computer to follow, and
organizing these instructions into groups known as functions.
We normally use flowcharts to organize these actions and
represent the flow of control from one action to another.
• In a multi-function program, many important data items are
placed as global so that they may be accessed by all the
functions. Each function may have its own local data.
Global data are more vulnerable to an inadvertent change
by a function. In a large program it is very difficult to identify
what data is used by which function. In case we need to
revise an external data structure, we also need to revise all
functions that access the data. This provides an opportunity
for bugs to creep in.
• Another serious drawback with the procedural approach is
that we do not model real world problems very well. This is
because functions are action-oriented and do not really
corresponding to the element of the problem.
Characteristics of
procedure-oriented
programming
• Emphasis is on doing things
(algorithms).
• Large programs are divided into
smaller programs known as functions.
• Most of the functions share global
data.
• Data move openly around the system
from function to function.
• Functions transform data from one
form to another.
• Employs top-down approach in
program design.
Object Oriented
Paradigm
• The major motivating factor in the invention of object-
oriented approach is to remove some of the flaws
encountered in the procedural 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 function that operate on it,
and protects it from accidental modification from outside
function.
• OOP allows decomposition of a problem into a number of
entities called objects and then builds data and function
around these objects.
• The data of an object can be accessed only by the
function associated with that object. However, function
of one object can access the function of other objects.
Organization
of data and
function in
OOP
Characteristics of
object-oriented
programming
• Emphasis is on data rather than procedure.
• Programs are divided into what are known as
objects.
• Data structures are designed such that they
characterize the objects.
• Functions that operate on the data of an object
are ties together in the data structure.
• Data is hidden and cannot be accessed by
external function.
• Objects may communicate with each other
through function.
• New data and functions can be easily added
whenever necessary.
• Follows bottom up approach in program design.
Basic Concepts of Object Oriented
Programming
It is necessary to understand some of the concepts used
extensively in object-oriented programming. These include: •
Objects
• Classes
• Data abstraction and encapsulation
• Inheritance
• Polymorphism
• Dynamic binding
• Message passing
Objects
• 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 to handle.
• They may also represent user-defined data such as vectors, time
and lists.
• Programming problem is analyzed in term of objects and the nature
of communication between them.
• Program objects should be chosen such that they match closely
with the real-world objects.
• Objects take up space in the memory and have an associated
address like a record in Pascal, or a structure in c.
Objects
• When a program is executed, the objects interact by sending
messages to one another.
• For example, if “customer” and “account” are to object in a
program, then the customer object may send a message to
the count object requesting for the bank balance.
• Each object contain data, and code to manipulate data.
Objects can interact without having to know details of each
other’s data or code.
• It is a sufficient to know the type of message accepted, and
the type of response returned by the objects.
Object
Classes
• 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 with the help of class. In fact, objects are variables of the type class.
• 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 created.
• A class is thus a collection of objects similar types.
• For examples, Mango, Apple and orange members of class fruit. Classes are user-
defined that types and behave like the built-in types of a programming language.
• The syntax used to create an object is not different then the syntax used to create
an integer object in C.
Classes
• If fruit has been defines as a class, then the statement
Fruit Mango;
Will create an object mango belonging to the class fruit.
Data Abstraction and Encapsulation
• The wrapping up of data and function into a single unit (called
class) is known as encapsulation.
• Data and encapsulation is the most striking feature of a class.
• The data is not accessible to the outside world, and only those
functions which are wrapped in the class can access it.
• These functions 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 or information hiding.
Data Abstraction and Encapsulation
• Abstraction refers to the act of representing essential features
without including the background details or explanation.
• Classes use the concept of abstraction and are defined as a
list of abstract attributes such as size, wait, and cost, and
function operate on these attributes.
• They encapsulate all the essential properties of the object that
are to be created.
• The attributes are some time called data members because
they hold information.
• The functions that operate on these data are sometimes
called methods or member function.
Inheritance
• Inheritance is the process by which objects of one class
acquired the properties of objects of another classes.
• It supports the concept of hierarchical classification. For
example, the bird, ‘robin’ is a part of class ‘flying bird’
which is again a part of the class ‘bird’.
• The principal behind this sort of division is that each
derived class shares common characteristics with the class
from which it is derived.
Inheritance
Inheritance
• 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 feature of both the classes.
• The real appeal and power of the inheritance mechanism is that it
allows the programmer to reuse a class i.e almost, but not exactly,
what he wants, and to tailor the class in such a way that it does not
introduced any undesirable side-effects into the rest of classes