Programming Paradigms/Models
Paradigm defines a model or way of programming
We will discuss the following three paradigms Imperative/Procedural Paradigm Declarative Paradigm Object Oriented Paradigm
Procedural Units Local versus Global Variables Formal versus Actual Parameters Passing parameters by value versus
reference Procedures versus Functions
6-5
Object Oriented Paradigm
In this approach all real world things are considered as an object. Each object has a certain set of qualities/ attributes and each object can perform some job/method. Thus if I have an object CAR then Car has its color, engine#, make, model etc as attributes and its methods can be drive(), stop() etc
Examples include C++, Java etc
Declarative Programming Approach
It emphasizes the question “What is the problem?” rather than “What algorithm is required for solving the problem?” Here a general problem solving approach is developed that can solve a number of problems. These languages are difficult to design and are special purpose by nature
PROLOG (Programming LOGic) is an example
Declarative Programming
Resolution: Combining two or more statements to produce a new statement (that is a logical consequence of the originals). Example: (P OR Q) AND (R OR Q)
resolves to (P OR R) Resolvent: A new statement deduced by
resolution Clause form: A statement whose elementary
components are connected by the Boolean operation OR
Unification: Assigning a value to a variable so that two statements become “compatible.” 6-13
Prolog Fact: A Prolog statement establishing a
fact Consists of a single predicate Form: predicateName(arguments).
Example: parent(bill, mary). Rule: A Prolog statement establishing a
general rule Form: conclusion :- premise.
:- means “if” Example: wise(X) :- old(X). Example: faster(X,Z) :- faster(X,Y), faster(Y,Z).
6-14
Top Related