0% found this document useful (0 votes)
6 views

Chapter One 1.1 Type of Paradigm

Chapter One introduces various programming paradigms, focusing on imperative, procedural, object-oriented, declarative, logic, functional, and database programming. Each paradigm is defined by its methodology for solving problems, with examples and advantages provided for each. The chapter emphasizes the importance of understanding these paradigms to effectively utilize programming languages in different contexts.

Uploaded by

Woldeab Bisrat
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

Chapter One 1.1 Type of Paradigm

Chapter One introduces various programming paradigms, focusing on imperative, procedural, object-oriented, declarative, logic, functional, and database programming. Each paradigm is defined by its methodology for solving problems, with examples and advantages provided for each. The chapter emphasizes the importance of understanding these paradigms to effectively utilize programming languages in different contexts.

Uploaded by

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

Chapter One

Introduction to Object Oriented Programming

1.1 Type of Programming Paradigms

Paradigm can also be termed as method to solve some problem or do some task. A programming
paradigm is the process of writing code in an organized manner based on some specific
methodology/method using programming language. Each language is used as a tool for solving a problem
and has its own unique style that uses a programming paradigm. It is an approach to solve problem using
some programming language or also we can say it is a method to solve a problem using tools and
techniques that are available to us following some approach. There are lots for programming language
that are known but all of them need to follow some strategy when they are implemented and this
methodology/strategy is paradigms. Apart from varieties of programming language there are lots of
paradigms to fulfill each and every demand. They are discussed below:

1. Imperative programming paradigm: It is one of the oldest programming paradigm. When you go
shopping, you usually write down the name of the things you need to buy before reaching the mall.
Similarly, this paradigm consists of a list of programming statements.

They are first executed, and then the results are stored in a variable. It is more of a line-by-line instruction
given to the computer.
It performs step by step task by changing state. The main focus of this paradigm is on how to achieve the
goal. The paradigm consist of several statements and after execution of all the result is stored. Let us
understand imperative programming using a C++ program that gives us factorial of a number.

Example:

#include<iostream>

using namespace std;

int main(){

int fact=1;

fact*=1;

fact*=2;

fact*=3;

fact*=4;

fact*=5;

fact*=6;

fact*=7;

fact*=8;

cout<<"Factorial of 8 is : "<<fact;

return 0;
}

Output:

In this example, we give a line-by-line task to perform by the computer with proper instructions. This
type of paradigm takes the order of the steps into consideration because different arrangements can
produce different results.

Advantages:

1. Very simple to implement


2. It contains loops, variables etc.

Disadvantage:

1. Complex problem cannot be solved


2. Less efficient and less productive
3. Parallel programming is not possible

Examples of Imperative programming paradigm:

C : developed by Dennis Ritchie and Ken Thompson


Fortran : developed by John Backus for IBM
Basic : developed by John G Kemeny and Thomas E Kurtz
// average of five number in C

int marks[5] = { 12, 32, 45, 13, 19 } int sum = 0;


float average = 0.0;
for (int i = 0; i < 5; i++) {
sum = sum + marks[i];
}
average = sum / 5;
Imperative programming is divided into three broad categories: Procedural, OOP and parallel processing.
These paradigms are as follows:

 Procedural programming paradigm – This paradigm emphasizes on procedure in terms


of under lying machine model. There is no difference in between procedural and imperative
approach. It has the ability to reuse the code.

This programming paradigm follows imperative programming with procedural calls. These calls direct
the system to perform the required tasks. Each procedure or so-called function can have multiple
commands to be executed. The function, once defined, can be called as many times as needed to perform
the same operation.

Procedural programming is considered the best for people starting to learn to code. Beginners can start
with procedural programming as it is simple, efficient, requires less memory, and is easier to keep track
of control flow. Factorial of n number is the best example of procedural programming paradigm.

Examples of Procedural programming paradigm:

C : developed by Dennis Ritchie and Ken Thompson


C++ : developed by Bjarne Stroustrup
Java : developed by James Gosling at Sun Microsystems
ColdFusion : developed by J J Allaire
Pascal : developed by Niklaus Wirth
C++
#include <iostream>
using namespace std;
int main()
{
int i, fact = 1, num;
cout << "Enter any Number: ";
cin >> number;
for (i = 1; i <= num; i++) {
fact = fact * i;
}
cout << "Factorial of " << num << " is: " << fact << endl;
return 0;
}
Then comes OOP,

 Object oriented programming – This is the most widely used and most popular
programming paradigm. Class, Abstraction, Encapsulation, Inheritance, and Polymorphism
form the backbone of Object-Oriented Programming (OOP). The program is written in this
paradigm as a collection of classes and object which are meant for communication. The
smallest and basic entity is object and all kind of computation is performed on the objects
only. Objects can have data associated with them called attributes and actions they can
perform using methods. More emphasis is on data rather procedure. It can handle almost all
kind of real life problems which are today in scenario.

Advantages:

 Data security
 Inheritance
 Code reusability
 Flexible and abstraction is also present

Examples of Object Oriented programming paradigm:

Simula : first OOP language


Java : developed by James Gosling at Sun Microsystems
C++ : developed by Bjarne Stroustrup
Objective-C : designed by Brad Cox
Visual Basic .NET : developed by Microsoft
Python : developed by Guido van Rossum
Ruby : developed by Yukihiro Matsumoto
Smalltalk : developed by Alan Kay, Dan Ingalls, Adele Goldberg
C++
// C++ program for the above approach
#include <bits/stdc++.h>
using namespace std;

// Class Signup
class Signup {
int userid;
string name;
string emailid;
char sex;
long mob;

public:
// Function to create and object using
// the parameters
void create(int userid, string name, string emailid,
char sex, long mob)
{
cout << "Welcome to GeeksforGeeks\nLets create "
"your account\n";
this->userid = 132;
this->name = "Radha";
this->emailid = "[email protected]";
this->sex = 'F';
this->mob = 900558981;
cout << "your account has been created" << endl;
}
};

// Driver Cpde
int main()
{
cout << "GfG!" << endl;

// Creating Objects
Signup s1;
s1.create(22, "riya", "[email protected]", 'F', 89002);

return 0;
}
Java
Python3
C#
Javascript
Output
GfG!
Welcome to GeeksforGeeks
Lets create your account

your account has been created

 Parallel processing approach – Parallel processing is the processing of program


instructions by dividing them among multiple processors. A parallel processing system
possess many numbers of processor with the objective of running a program in less time by
dividing them. This approach seems to be like divide and conquer. Examples are NESL (one
of the oldest one) and C/C++ also supports because of some library function.

2. Declarative programming paradigm: It is divided as Logic, Functional, and Database. In computer


science the declarative programming is a style of building programs that expresses logic of computation
without talking about its control flow. The programmer must specify what the program must accomplish
but need not specify how it must be implemented. The focus is on what needs to be done rather how it
should be done basically emphasize on what code is actually doing. It just declares the result we want
rather how it has be produced. This is the only difference between imperative (how to do) and declarative
(what to do) programming paradigms. Getting into deeper we would see logic, functional and database.

 Logic programming paradigms – It can be termed as abstract model of computation. It


would solve logical problems like puzzles, series etc. The logic programming paradigm uses
logic-based statements to convey facts and rules. Logical inferences are made of instructions
or logic statements to do computation. Atomic statements are built using these predicate
statements. In logic programming we have a knowledge base which we know before and
along with the question and knowledge base which is given to machine, it produces result.
In normal programming languages, such concept of knowledge base is not available but
while using the concept of artificial intelligence, machine learning we have some models
like Perception model which is using the same mechanism.

In logical programming the main emphasize is on knowledge base and the problem. The
execution of the program is very much like proof of mathematical statement, e.g., Prolog

Let us take the statement, “abebe is a human. All humans are animals, So abebe is an animal”.
So in prolog code:-
Human(abebe)
Animal(X) :-human(X)
To test the program, we can ask if Abebe is an animal.
?- animal(abebe)

 Functional programming paradigms– this paradigm is built upon mathematical


functions. It solves problems using these mathematical functions as program
components. This programming is used while working with concurrency and
parallelism.
The functional programming paradigms has its roots in mathematics and it is language
independent. The key principle of this paradigms is the execution of series of
mathematical functions. The central model for the abstraction is the function which
are meant for some specific computation and not the data structure. Data are loosely
coupled to functions. The function hide their implementation. Function can be
replaced with their values without changing the meaning of the program. Some of the
languages like Perl, JavaScript mostly uses this paradigm.

Examples of Functional programming paradigm:

JavaScript : developed by Brendan Eich


Haskell : developed by Lennart Augustsson, Dave Barton
Scala : developed by Martin Odersky
Erlang : developed by Joe Armstrong, Robert Virding
Lisp : developed by John Mccarthy
ML : developed by Robin Milner
Clojure : developed by Rich Hickey
The next kind of approach is of Database.

 Database/Data Driven Programming approach – This programming methodology is


based on data and its movement. Program statements are defined by data rather than hard-
coding a series of steps. A database program is the heart of a business information system
and provides file creation, data entry, update, query and reporting functions. There are
several programming languages that are developed mostly for database application. For
example SQL. It is applied to streams of structured data, for filtering, transforming,
aggregating (such as computing statistics), or calling other programs. So it has its own wide
application.

CREATE DATABASE databaseAddress;


CREATE TABLE Addr (
PersonID int,
LastName varchar(200),
FirstName varchar(200),
Address varchar(200),
City varchar(200),
State varchar(200)
);

You might also like