Introduction of Programming Paradigms: Paradigm Can Also Be Termed As Method To Solve Some Problem or Do Some Task
Introduction of Programming Paradigms: Paradigm Can Also Be Termed As Method To Solve Some Problem or Do Some Task
Paradigm can also be termed as method to solve some problem or do some task.
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 fulfil each and every
It is one of the oldest programming paradigm. It features close relation relation to
the program state through assignment statements. It performs step by step task by
changing state. The main focus is on how to achieve the goal. The paradigm consist of
Advantage:
Disadvantage:
average = sum / 5;
Imperative programming is divided into three broad categories: Procedural, OOP and
int main()
fact = fact * i;
cout << "Factorial of " << num << " is: " << fact <<
endl;
return 0;
Intention of object oriented modeling and design is to learn how to apply object
models organized around real world concepts. The fundamental construct is the object,
Purpose of Models:
There are 3 types of models in the object oriented modeling and design are: Class
Model, State Model, and Interaction Model. These are explained as following below.
1. Class Model:
The class model shows all the classes present in the system. The class
model shows the attributes and the behavior associated with the objects.
The class diagram is used to show the class model.The class diagram
shows the class name followed by the attributes followed by the functions
or the methods that are associated with the object of the class.Goal in
constructing class model is to capture those concepts from the real world
that are important to an application.
2. State Model:
State model describes those aspects of objects concerned with time and
the sequencing of operations – events that mark changes, states that
define the context for events, and the organization of events and
states.Actions and events in a state diagram become operations on objects
in the class model. State diagram describes the state model.
3. Interaction Model:
Interaction model is used to show the various interactions between objects,
how the objects collaborate to achieve the behavior of the system as a
whole.
The following diagrams are used to show the interaction model:
○ Use Case Diagram
○ Sequence Diagram
○ Activity Diagram
Object Oriented Design
Object oriented design started right from the moment computers were invented.
Programming was there, and programming approaches came into the picture.
At the beginning of the computing era, programming was usually limited to machine
language programming. Machine language means those sets of instructions that are
specific to a particular machine or processor, which are in the form of 0’s and 1’s. These
are sequences of bits (0100110…). But it’s quite difficult to write a program or develop
It’s actually impossible to develop software used in today’s scenarios with sequences of
bits. This was the main reason programmers moved on to the next generation of
programming languages, developing assembly languages, which were near enough to
the English language to easily understand. These assembly languages were used in
flourished and ruled over the industry, but it was not enough. Again, programmers came
Structured Programming –
The basic principle of the structured programming approach is to divide a program into
functions and modules. The use of modules and functions makes the program more
understandable and readable. It helps to write cleaner code and to maintain control over
the functions and modules. This approach gives importance to functions rather than
data. It focuses on the development of large software applications, for example, C was
used for modern operating system development. The programming languages: PASCAL
(introduced by Niklaus Wirth) and C (introduced by Dennis Ritchie) follow this approach.
This approach is also known as the top-down approach. In this approach, a program is
divided into functions that perform specific tasks. This approach is mainly used for
medium-sized applications. Data is global, and all the functions can access global data.
The basic drawback of the procedural programming approach is that data is not
secured because data is global and can be accessed by any function. Program control
flow is achieved through function calls and goto statements. The programming
These programming constructs were developed in the late 1970s and 1980s. There
were still some issues with these languages, though they fulfilled the criteria of
requirements were at that time. They seem to be over-generalised and don’t correlate
solution.
The OOP concept was basically designed to overcome the drawback of the above
demand was increased, but still, conventional methods were used. This new approach
Object-oriented programming (OOP) is nothing but that which allows the writing of
programs with the help of certain classes and real-time objects. We can say that this
approach is very close to the real-world and its applications because the state and
behaviour of these classes and objects are almost the same as real-world objects.
Let’s go deeper into the general concepts of OOP, which are given below:
What Are Class & Object?
It is the basic concept of OOP; an extended concept of the structure used in C. It is an
abstract and user-defined data type. It consists of several variables and functions. The
primary purpose of the class is to store data and information. The members of a class
define the behaviour of the class. A class is the blueprint of the object, but also, we can
say the implementation of the class is the object. The class is not visible to the world,
Class car
{
int car_id;
char colour[4];
float engine_no;
double distance;
void distance_travelled();
float petrol_used();
char music_player();
void display();
}
Here, the class car has properties car_id, colour, engine_no and distance. It resembles
the real-world car that has the same specifications, which can be declared public
(visible to everyone outside the class), protected and private (visible to none). Also,
there are some methods such as distance_travelled(), petrol_used(), music_player() and
display(). In the code given below, the car is a class and c1 is an object of the car.
class car {
public:
int car_id;
double distance;
void distance_travelled();
Data Abstraction –
Abstraction refers to the act of representing important and special features without
including the background details or explanation about that feature. Data abstraction
1. Physical Level:
It describes how the records are stored, which are often hidden from the
user. It can be described with the phrase, “block of storage.”
2. Logical Level:
It describes data stored in the database and the relationships between the
data. The programmers generally work at this level as they are aware of the
functions needed to maintain the relationships between the data.
3. View Level:
Application programs hide details of data types and information for security
purposes. This level is generally implemented with the help of GUI, and
details that are meant for the user are shown.
Encapsulation –
(OOP). It describes the idea of wrapping data and the methods that work on data within
one unit, e.g., a class in Java. This concept is often used to hide the internal state
class, called the parent class. When we write a class, we inherit properties from other
classes. 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 which
possesses it. Inheritance allows the user to reuse the code whenever possible and
Polymorphism –
Polymorphism is the ability of data to be processed in more than one form. It allows the
performance of the same task in various ways. It consists of method overloading and
method overriding, i.e., writing the method once and performing a number of tasks
#include <iostream>
using namespace std;
void output(float);
void output(int);
void output(int, float);
int main()
{
cout << "\nGfG!\n";
int a = 23;
float b = 2.3;
output(a);
output(b);
output(a, b);
return 0;
}
Some important points to know about OOP:
Advantages of OOPs –
Disadvantages of OOP –
Class: The building block of C++ that leads to Object-Oriented programming is a Class.
It is a user-defined data type, which holds its own data members and member functions,
which can be accessed and used by creating an instance of that class. A class is like a
For Example: Consider the Class of Cars. There may be many cars with different names
and brand 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
We can say that a Class in C++ is a blue-print representing a group of objects which
Object: A
n Object is an identifiable entity with some characteristics and behaviour. An
class person
{
char name[20];
int id;
public:
void getdetails(){}
};
int main()
{
person p1; // p1 is a object
}
Object take up space in memory and have an associated address like a record in pascal
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
defined as binding together the data and the functions that manipulate them.
like the accounts section, finance section, sales section etc. The finance section
handles all the financial transactions and keeps records of all the data related to
finance. Similarly, the sales section handles all the sales-related activities and keeps
records of all the sales. Now there may arise a situation when for some reason an
official from the finance section needs all the data about sales in a particular month. In
this case, he is not allowed to directly access the data of the sales section. He will first
have to contact some other officer in the sales section and then request him to give the
particular data. This is what encapsulation is. Here the data of the sales section and the
employees that can manipulate them are wrapped under a single name “sales section”.
hides the data. In the above example, the data of any of the section like sales, finance or
Abstraction: Data abstraction is one of the most essential and important features of
information and hiding the details. 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 accelerator the speed is actually
increasing, he does not know about the inner mechanism of the car or the
implementation of accelerator, brakes etc in the car. This is what abstraction is.
Polymorphism: The word polymorphism means having many forms. In simple words,
one form.
A person at the same time can have different characteristic. Like a man at the same
Example: Suppose we have to write a function to add some integers, some times there
are 2 integers, some times there are 3 integers. We can write the Addition Method with
the same name having different parameters, the concerned method will be called
according to parameters.
Inheritance: The capability of a class to derive properties and characteristics from
another class is called Inheritance. Inheritance is one of the most important features of
Object-Oriented Programming.
● Sub Class: The class that inherits properties from another class is called
Sub class or Derived Class.
● Super Class:The class whose properties are inherited by sub class is called
Base Class or Super class.
● Reusability: Inheritance supports the concept of “reusability”, i.e. when we
want to create a new class and there is already a class that includes some
of the code that we want, we can derive our new class from the existing
class. By doing this, we are reusing the fields and methods of the existing
class.
Example: Dog, Cat, Cow can be Derived Class of Animal Base Class.
Message Passing: Objects communicate with one another by sending and receiving
procedure and therefore will invoke a function in the receiving object that generates the
desired results. Message passing involves specifying the name of the object, the name
Abstraction:
In OOPs, Abstraction is that the method of getting info. the information needed
will be taken in such the simplest way that solely the required components are
extracted, and also the ones that are considered less significant are unnoticed.
Or the unessential info will be drained dead set keep solely the sensitive
information intact. during this case, most of the classes don’t have any sort of
interface stage. one thing that doesn’t exist and is just a concept is named
Example of Abstraction:
#include <iostream>
using namespace std;
class Summation {
private:
// private variables
int a, b, c;
public:
void sum(int x, int y)
{
a = x;
b = y;
c = a + b;
cout<<"Sum of the two number is : "<<c<<endl;
}
};
int main()
{
Summation s;
s.sum(5, 4);
return 0;
Output:
Sum of the two number is: 9
In the this example, we can see that abstraction has achieved by using class. The
class 'Summation' holds the private members a, b and c, which are only
Encapsulation:
Encapsulation is the process or method to contain the information. The info, it
provides is that the solely the one that is critical and every one the opposite data
that is unsuitable is hidden already. during this case, the matter determination is
data in a single entity or unit along with a method to protect information from
of solely the essential options of a product. for example, once someone is
mistreatment software package they are doing not recognize what the secret
writing is, they solely use the mandatory functions that result from the secret
Example of Encapsulation:
#include <iostream>
using namespace std;
class EncapsulationExample {
private:
// we declare a as private to hide it from outside
int a;
public:
// set() function to set the value of a
void set(int x)
{
a = x;
}
// main function
int main()
{
EncapsulationExample e1;
e1.set(10);
cout<<e1.get();
return 0;
}
Output:
10
In the this program, the variable a is made private so that this variable can be
accessed and manipulated only by using the methods get() and set() that are
present within the class. Therefore we can say that, the variable a and the
methods set() as well as get() have binded together that is nothing but
encapsulation.
4
We can implement Whereas encapsulation can be
.
abstraction using implemented using by access
abstract class and modifier i.e. private, protected and
interfaces. public.
In abstraction,
and interfaces.
The objects that help to Whereas the objects that result in
6
perform abstraction are encapsulation need not be
.
encapsulated. abstracted.