Unit 2
Unit 2
PARADIGMS
What is a computer program
• A computer program is a set of instructions for a computer to perform a task which is
written using a programming language. A programming paradigm can categorize the
programming language depending on language features.
• The code is divided into functions or modules. It is also known as modular programming. Modules
or functions are a set of statements which performs a sub task.
• As each task is a separate module, it is easy for the programmer to test and debug. It is also easy to
do modifications without changing the whole program.
• When changing the code, the programmer has to concentrate only on the specific module.
• Procedural programming. Defines modules as procedures or functions that are called with a set of
parameters to perform a task. A procedural language begins a process, which is then given data.
• Model-based programming. The most common example of this is database query languages. In
database programming, units of code are associated with steps in database access and update or run
when those steps occur.
What is unstructured programming
• Unstructured Programming is a type of programming that generally executes in sequential
order i.e., these programs just not jumped from any line of code and each line gets executed
sequentially.
• In Unstructured Programming, the code is written as a single whole block. The whole program is
taken as a single unit. It is harder to do changes in the program.
• This paradigm was used in earlier versions of BASIC, COBOL, and FORTRAN. Unstructured
programming languages have a limited number of data types like numbers, arrays, strings.
Output :
Addition = 15
Subtraction = 5
Difference between structured and unstructured
programming
Object Oriented Programming
• Object-Oriented Programming or OOPs refers to languages that use objects
in programming. Object-oriented programming aims to implement real-
world entities like inheritance, hiding, polymorphism, etc in programming.
• The main aim of OOP is to bind together the data and the functions that
operate on them so that no other part of the code can access this data except
that function.
• OOPs Concepts:
• Class
• Objects
• Data Abstraction
• Encapsulation
• Inheritance
• Polymorphism
Class
• A class is a user-defined data type. It consists of data members and member
functions, which can be accessed and used by creating an instance of that
class.
• It represents the set of properties or methods that are common to all objects
of one type. A class is like a blueprint for an object.
• For Example: Consider the Class of Cars. There may be many cars with
different names and brands but all of them will share some common
properties like all of them will have 4 wheels, Speed Limit, Mileage range,
etc. So here, Car is the class, and wheels, speed limits, mileage are their
properties.
Object
• It is a basic unit of Object-Oriented Programming and represents the real-life entities. An
Object is an instance of a Class. When a class is defined, no memory is allocated but when it is
instantiated (i.e. an object is created) memory is allocated.
• An object has an identity, state, and behavior. Each object contains data and code to manipulate
the data. Objects can interact without having to know details of each other’s data or code, it is
sufficient to know the type of message accepted and type of response returned by the objects.
• For example “Dog” is a real-life Object, which has some characteristics like color, Breed,
Bark, Sleep, and Eats.
Data Abstraction
• Data abstraction is one of the most essential and important features of object-oriented
programming. Data abstraction refers to providing only essential information about the
data to the outside world, hiding the background details or implementation.
• Consider a real-life example of a man driving a car. The man only knows that pressing
the accelerators will increase the speed of the car or applying brakes will stop the car, but
he does not know about how on pressing the accelerator the speed is increasing, he does
not know about the inner mechanism of the car or the implementation of the accelerator,
brakes, etc in the car. This is what abstraction is.
Encapsulation
• So when we create a class, we do not need to write all the properties and functions again and
again, as these can be inherited from another class that possesses it. Inheritance allows the user to
reuse the code whenever possible and reduce its redundancy.
Polymorphism
• The word polymorphism means having many forms. In simple words, we
can define polymorphism as the ability of a message to be displayed in more
than one form.
• For example, A person at the same time can have different characteristics.
Like a man at the same time is a father, a husband, an employee. So the same
person posses different behavior in different situations. This is called
polymorphism.
Characteristics of good computer program
A good programming language must be simple and easy to learn and use.
Characteristics:
Readability: More user-friendly approach. The program should be written in such a way that it makes other programmers or
Efficiency: Every program requires certain processing time and memory to process the instructions and data. As the processing
power and memory are the most precious resources of a computer, a program should be laid out in such a manner that it utilizes
Structural: To develop a program, the task must be broken down into a number of subtasks.
Flexibility: A program should be flexible enough to handle most of the changes without having to rewrite the entire program.
Most of the programs are developed for a certain period and they require modifications from time to time.
For example, in case of payroll management, as the time progresses, some employees may leave the company while some others may
join. Hence, the payroll application should be flexible enough to incorporate all the changes without having to reconstruct the entire
application.
Generality: Apart from flexibility, the program should also be general. Generality means that if a program
is developed for a particular task, then it should also be used for all similar tasks of the same domain. For
example, if a program is developed for a particular organization, then it should suit all the other similar
organizations.
Even if a program is developed following the best programming practices, it will be rendered useless if the
end user is not able to fully utilize the functionality of the application. A well-documented application is
also useful for other programmers because even in the absence of the author, they can understand it.
operations concisely. A verbose language is generally not liked by programmers, because they need to