Abstraction
is one of the most powerful and vital features provided by object-oriented C++
programming language. With this feature the programmer can abstract both data
and code when needed.
The
concept of abstraction relates to the idea of hiding data that are not needed
for presentation. The main idea behind data abstraction is to give a clear
separation between properties of data type and the associated implementation
details. This separation is achieved in order that the properties of the
abstract data type are visible to the user interface and the implementation
details are hidden. Thus, abstraction forms the basic platform for the creation
of user-defined data types called objects. Data abstraction is the process of
refining data to its essential form. An Abstract Data Type is defined as a data
type that is defined in terms of the operations that it supports and not in
terms of its structure or implementation.
In object-oriented programming language C++, it is possible to create and provide an interface that accesses only certain elements of data types. The programmer can decide which user to give or grant access to and hide the other details. This concept is called data hiding which is similar in concept to data abstraction.
In object-oriented programming language C++, it is possible to create and provide an interface that accesses only certain elements of data types. The programmer can decide which user to give or grant access to and hide the other details. This concept is called data hiding which is similar in concept to data abstraction.
Types of Abstraction:
There
are two broad types of abstraction; functional abstraction and data abstraction.
The main difference between functional abstraction and data abstraction is that
functional abstraction refers to a function that can be used without taking
into account how the function is implemented. Data abstraction refers to the
data that can be used without taking into account how the data are stored. There
is also a difference in the way the access takes place in functional
abstraction and data abstraction. In functional abstraction, access to the
function is provided through a specific interface defined to invoke the
function. In contrast, in data abstraction, access to the data is provided
through a specific set of operations defined to examine and manipulate the
data. For instance, when a programmer is using C++ standard data types, this
means that users are using the concept of data abstraction. When using data
types, the users are not concerned with how the data is stored but they are
concerned with what operations are provided and what properties are supported.
Reasons for the need of Abstraction:
Flexibility in approach:
By hiding data or abstracting details that are not needed for presentation, the programmer achieves greater flexibility in approach.
Enhanced Security:
Abstraction gives access to data or details that are needed by users and hide the implementation details, giving enhanced security to application.
Easier Replacement:
With the concept of abstraction in object-oriented programming language, it is possible to replace code without recompilation. This makes the process easier and saves time for users.
Modular Approach:
In object-oriented programming language C++, the abstraction concept helps users to divide the project application into modules and test each of them separately. Then all modules are integrated and ultimately tested together. This approach makes the application development easier.
How to achieve Abstraction:
By hiding data or abstracting details that are not needed for presentation, the programmer achieves greater flexibility in approach.
Enhanced Security:
Abstraction gives access to data or details that are needed by users and hide the implementation details, giving enhanced security to application.
Easier Replacement:
With the concept of abstraction in object-oriented programming language, it is possible to replace code without recompilation. This makes the process easier and saves time for users.
Modular Approach:
In object-oriented programming language C++, the abstraction concept helps users to divide the project application into modules and test each of them separately. Then all modules are integrated and ultimately tested together. This approach makes the application development easier.
How to achieve Abstraction:
There are various ways of achieving
abstraction in object-oriented programming language C++. One approach is to
take modular based code that is broken apart into smaller segments, known as
functions. This functional or modular approach helps the code to be reused
again and again when needed. For example, a programmer might write a function
for computing an average and another programmer might write a function for
computing salary. These functions can be reused when needed, by anyone. The
modular based approach helps to centralize all data of a similar type, under
the control of a type module. Defining module types allow the module to be an
abstract data type. In many other programming languages, there is a small
drawback associated with the approach to accessing module type. The abstraction
principles used in the object-oriented approach are:
- Classification/instantiation,
- aggregation/decomposition,
- generalization/specialization
No comments:
Write comments