Java Reference
In-Depth Information
Logic Paradigm
Unlike the imperative paradigm, the logic paradigm focuses on the “what” part of the problem rather than how to
solve it. All you need to specify is what needs to be solved. The program will figure out the algorithm to solve it. The
algorithm is of less importance to the programmer. The primary task of the programmer is to describe the problem as
closely as possible. In the logic paradigm, a program consists of a set of axioms and a goal statement. The set of axioms
is the collection of facts and inference rules that make up a theory. The goal statement is a theorem. The program uses
deductions to prove the theorem within the theory. Logic programming uses a mathematical concept called a relation
from set theory. A relation in set theory is defined as a subset of the Cartesian product of two or more sets. Suppose
there are two sets, Persons and Nationality , which are defined as follows:
Person = {John, Li, Ravi}
Nationality = {American, Chinese, Indian}
The Cartesian product of the two sets, denoted as Person x Nationality , would be another set, as shown:
Person x Nationality = {{John, American}, {John, Chinese},
{John, Indian}, {Li, American}, {Li, Chinese},
{Li, Indian}, {Ravi, American}, {Ravi, Chinese},
{Ravi, Indian}}
Every subset of Person x Nationality is another set that defines a mathematical relation. Each element of a
relation is called a tuple. Let PersonNationality be a relation defined as follows:
PersonNationality = {{John, American}, {Li, Chinese}, {Ravi, Indian}}
In logic programming, you can use the PersonNationality relation as the collection of facts that are known to be
true. You can state the goal statement (or the problem) like
PersonNationality(?, Chinese)
which means “give me all names of people who are Chinese.” The program will search through the
PersonNationality relation and extract the matching tuples, which will be the answer (or the solution) to your
problem. In this case, the answer will be Li .
Prolog is an example of a programming language that supports the logic paradigm.
Object-Oriented Paradigm
In the object-oriented (OO) paradigm, a program consists of interacting objects. An object encapsulates data and
algorithms. Data defines the state of an object. Algorithms define the behavior of an object. An object communicates
with other objects by sending messages to them. When an object receives a message, it responds by executing one of
its algorithms, which may modify its state. Contrast the object-oriented paradigm with the imperative and functional
paradigms. In the imperative and functional paradigms, data and algorithms are separated, whereas in the object-oriented
paradigm, data and algorithms are not separate; they are combined in one entity, which is called an object.
Classes are the basic units of programming in the object-oriented paradigm. Similar objects are grouped into
one definition called a class. A class' definition is used to create an object. An object is also known as an instance of
the class. A class consists of instance variables and methods. The values of instance variables of an object define the
state of the object. Different objects of a class maintain their states separately. That is, each object of a class has its
own copy of the instance variables. The state of an object is kept private to that object. That is, the state of an object
cannot be accessed or modified directly from outside the object. Methods in a class define the behavior of its objects.
A method is like a procedure (or subroutine) in the procedural paradigm. Methods can access/modify the state of the
object. A message is sent to an object by invoking one of its methods.
 
Search WWH ::




Custom Search