ABSTRACTION
The essential features of an entity are known as abstraction.
A feature may be either an attribute reflecting a property (or state or data)
or an operation reflecting a method (or behavior or function). The features
such as things in the trunk of a car, the medical history of the manager
traveling in the car, and the working mechanism of the car engine are not
necessary for the driver. The essential features of an entity in the
perspective of the user define abstraction. A good abstraction is achieved by
having:
·
meaningful
name such as driver reflecting the function
·
minimum
and at the same time complete features
·
coherent
features
Abstraction specifies necessary and
sufficient descriptions rather than implementation details. It results in separation
of interface and implementation.
COMPARISON OF NATURAL AND CONVENTIONAL PROGRAMMING METHODS
In
conventional programming, structured or procedural languages are used. In the
structured programming approach, functions are defined according to the algorithm
to solve the problem. Here, function abstractions are concentrated. A function
is applied to some data to perform the actions on data. This approach may be called
a data-driven approach, which involves operator/operand concept. It
depends on the solution domain because the algorithm (solution) is closer to
the coding of the program. The relationship between the programmer and the
program is emphasized in the data-driven approach. The solution is
solution-domain specific. Conventional programming follows the following
principles:
·
operator-operand concept
·
function abstraction
·
separation of data and functions
The
development of the algorithm is given prime importance in conventional
programming. The
importance
of data is not considered and hence, sometimes critical data having global
access may result in miserable output. The abstraction followed is function
abstraction and not data abstraction. Data and functionalities are considered
as two separate parts.
But,
in the natural way of solving real-world problems, the responsibility is
delegated to an agent. The solution is proposed instead of developing an
algorithm. The problem is solved by having a number of agents (interfaces). The
interface part is the user’s viewpoint, and hence the solution is not closer to
the coding of the program. The real-world problem is solved using a
responsibility-driven approach. In this approach, the relationship between the
user and the programmer is emphasized. Here, the solution is problem
domain-specific. The natural way of problem solving follows the following basic
principles:
·
message passing
·
abstraction
·
encapsulation
The
importance of data is realized through object-oriented technology, which
follows the natural way of solving problems. Data abstraction and data encapsulation
help to make the abstract view of the solution
with
information hiding. Data is given the proper importance and action is initiated
by message passing. Data and functionalities are put together resulting in
objects and a collection of interacting objects are used to solve the problem.
Object-oriented programming languages are developed based on object-oriented technology.
MODULARITY
The
complexity of a program can be reduced by partitioning the program into
individual modules. In object-oriented programming languages, classes and
objects form the logical structure of a system. Modules serve as the physical
containers in which the classes and objects are declared. Modularity is the
property of a system that has been decomposed into a set of cohesive and
loosely coupled modules. A module is an indivisible unit of software that can
be reused. The boundaries of modules are established to minimize the interfaces
among different parts of the development organization. Modules are frequently
used as an implementation technique for abstract data type. Abstract data type
is a theoretical concept and module is an implementation technique. Each class
is considered to be a module in OOP.
The
responsibilities of classes are defined by means of their attributes and
behavior. But a single object alone is not very useful. Higher order
functionality and complex behavior are achieved through interaction of objects
in different modules. Hence, interaction of objects is very important. Software
objects interact and communicate with each other by sending messages to each
other. The activities are initiated by the transmission of a message to an
object responsible for the action. The message encodes the request and the
information is passed along with the message as parameters. There are three
components to comprise a message:
·
The
receiver objects to whom the message is addressed.
·
The
name of the function performing the action.
·
The
parameters required by the function.
Interaction between objects is
possible with the help of message passing. In the case of distributed applications,
objects in different machines can also send and receive messages.
HOW
TO DESIGN A CLASS?
A
class is designed with a specific goal. Its purpose must be clear to the users.
An entity in solving a problem is categorized as a class if there is a need for
more than one instance of this class. Also, it is very important to entrust a
responsibility to an object. Presenting simply the behaviors such as reading
data and displaying data in a class is a poor design of a class. To perform
complex tasks, one class must jointly work with the other classes to perform
the task. This approach is known as collaboration among classes. The class must
be designed with essential attributes and behavior to reflect an idea in the
real world.
The
terms class and object are very important in object-oriented programming. A
class is a prototype or blueprint or model that defines the variables and
functions in it. The variables defined in a class represent the data, or
states, or properties, or attributes of a visible thing of
a certain type. Classes are user-defined data types. It is possible to create a
lot of objects of a class. The important advantages of classes are:
·
Modularity
·
Information hiding
·
Reusability
DESIGN
STRATEGIES IN OOP
Object-oriented
programming includes a number of powerful design strategies based on software
engineering
principles. Design strategies allow the programmers to develop complex systems
in a manageable form. They have been evolved out of decades of software
engineering experience. The basic design strategies embedded in object-oriented
programming are:
i.
Abstraction
ii.
Composition
iii.
Generalization
The
existing object-oriented programming languages support most of these features.
Composition
A
complex system is organized using a number of simpler systems. An organized
collection of smaller components interacting to achieve a coherent and common
behavior is known as composition. There are two types of composition:
1.
Association
2. Aggregation
Aggregation
considers the composed part as a single unit whereas association considers each
part of composition as a separate unit. For example, a computer is an
association of CPU, keyboard, and monitor. Each part is visible and manipulated
by the user. CPU is an aggregation of processor memory and control unit. The
individual parts are not visible and they cannot be manipulated by the user.
Both types of composition are useful. Aggregation provides greater security
because its structure is defined in advance and cannot be altered at runtime.
Association offers greater flexibility because the relationships among the visible
units can be redefined at run time. It adapts to changing conditions in its
execution environment by replacing one or more of its components. The two types
of composition are frequently used together. A computer is an example for
combination of both association and aggregation.
Generalization
Generalization
identifies the common properties and behaviors of abstractions. It is different
from abstraction. Abstraction is aimed at simplifying the description of an
entity, whereas generalization identifies commonalities among a set of
abstractions. Generalizations are important since they are like “laws” or
“theorems”, which lay the foundation for many things. Generalization helps to
develop software capturing the idea of similarity.
No comments:
Post a Comment