Different paradigms for problem solving, Need for OOP Paradigm
Q11. What is programming paradigms? Explain about different paradigms for problem solving.Answer :
Programming Paradigms
A programming paradigm is defined as a pattern or model of programming that includes the complete process of programming. It provides solutions to the problems within the framework. It involves a set of conceptual patterns that helps the user to generate an appropriate solution to a problem. There exists several programming paradigms and the programming techniques provided by each paradigm differs from one another. Whenever a solution is obtained using a programming paradigm, it is necessary to have a programming language to implement that process. Thus, every high level programming language consists of a programming paradigm. ;
Programming Paradigms for Problem Solving
The following are the mostly used programming paradigms,
(a) Imperative or procedural paradigm
(b) Functional paradigm
(c) Logical paradigm
(d) Object oriented paradigm.
(a) Imperative or Procedural Paradigm
Procedure oriented programming is a traditional programming paradigm which makes use of various high-level languages such as C, COBOL and FORTRAN. It consists of a set of functions. In this programming, a problem can be divided into a set of tasks. Each task can be performed by a function. A function consists of a set of instructions to perform the-required task. Along with these functions, main function is also available in this programming. The main function often consists of several instructions and the flow of execution starts from this function. The organization of procedure oriented programming is performed using a control flow which is as follows:
Figure: The Structure of Procedure Oriented Programming
Generally, functions are operated depending on the variables that are available in the program. Among these variables and functions, a relationship exist. A function may contain its own variables/data called as local variables/local data. These variables can be used only within the function. If two or more functions are intended to use similar variables, then they can be declared as
Advantages of Procedural Paradigm
- It is more efficient and popular paradigm.
- It is familiar than other paradigms.
- Debugging process is difficult.
- It doesn’t maintain proper sequential format.
(b) Functional Paradigm
Functional programming paradigm is a paradigm used for evaluating the expressions. These expressions are evaluated based on mathematical function composition. It mainly focuses on “what to solve” rather than “how to solve”. Here, every expression that is evaluated generates a value. This paradigm is based on lambda calculus. The lambda calculus function adds “I to its parameter as shown below,
(lambda
(x) (+ x1))
The above lambda calculus function can be represented in mathematical function as,f(x) =x+1
The functional programming paradigm does not Support step-by-step execution. Here, the output of one expression is given as the input to the succeeding expressions.
Advantages of Functional Paradigm:
- It eliminates the errors by decreasing the number of steps.
- It makes the functional oriented programming languages easy.
- It holds many referential transparency programs, therefore it is capable of receptive to mathematical proof and analysis.
- It has less efficiency.
- It’s processing speed is very slow because of its larger size.
(c) Logical Paradigm
A logical paradigm (or) rule based paradigm is the one in which the primary means of making computations is done by applying logical relations to given parameters. It can be either a variable (or) a character. It mainly focuses on predicate logic, wherein ‘relation’ is the basic concept. It is an enhanced technique of functional paradigm.
Example
X is the father of Y: Y is the brother of Z. Then X can be the father of Z also.
Every logical paradigm consists of three phases in order to solve the given problem.
- In the first phase of the given problem, a series of declarations (or) assertions need to be checked.
- Then, check whether the given statements are relevant.
- After checking, finally write the suitable query to execute the given problem.
- It reduces the number of steps in the program as it solves the problem logically by the system itself.
- It easily proves the validity of the given problem.
- It consumes a lot of time to execute certain tasks.
- It is very difficult to debug an error.
(d) Object Oriented Paradigm
Object oriented programming is an enhanced technique of procedure oriented programming. It is introduced to overcome the problems of procedure oriented programming. In actual terms, procedure oriented programming uses top-down approach. Whereas, object oriented programming uses bottom-up approach. It also reduces the complexities of procedure oriented programming.
The object oriented programming technique develops a program with a set of objects along with a well-defined interfaces to that object. A brief definition of an object oriented programming is that it is a data which controls the access to code. This technique also discusses about the way in which elements in a computer program must be organized and how these elements can interact with each other. To perform this, object-oriented programming uses various principles such as inheritance, data abstraction, encapsulation and polymorphism.
Advantages of Object Oriented Paradigm
- It is capable of visualizing the solutions to the given problems easily.
- Its encapsulation allows the objects to adapt and reuse the different programs.
- It requires more memory
- It requires more processions resources.